1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.google.android.exoplayer2.ui;
17 
18 import android.view.View;
19 import androidx.annotation.Nullable;
20 
21 /**
22  * Interface for time bar views that can display a playback position, buffered position, duration
23  * and ad markers, and that have a listener for scrubbing (seeking) events.
24  */
25 public interface TimeBar {
26 
27   /**
28    * Adds a listener for scrubbing events.
29    *
30    * @param listener The listener to add.
31    */
addListener(OnScrubListener listener)32   void addListener(OnScrubListener listener);
33 
34   /**
35    * Removes a listener for scrubbing events.
36    *
37    * @param listener The listener to remove.
38    */
removeListener(OnScrubListener listener)39   void removeListener(OnScrubListener listener);
40 
41   /**
42    * @see View#isEnabled()
43    */
setEnabled(boolean enabled)44   void setEnabled(boolean enabled);
45 
46   /**
47    * Sets the position increment for key presses and accessibility actions, in milliseconds.
48    * <p>
49    * Clears any increment specified in a preceding call to {@link #setKeyCountIncrement(int)}.
50    *
51    * @param time The time increment, in milliseconds.
52    */
setKeyTimeIncrement(long time)53   void setKeyTimeIncrement(long time);
54 
55   /**
56    * Sets the position increment for key presses and accessibility actions, as a number of
57    * increments that divide the duration of the media. For example, passing 20 will cause key
58    * presses to increment/decrement the position by 1/20th of the duration (if known).
59    * <p>
60    * Clears any increment specified in a preceding call to {@link #setKeyTimeIncrement(long)}.
61    *
62    * @param count The number of increments that divide the duration of the media.
63    */
setKeyCountIncrement(int count)64   void setKeyCountIncrement(int count);
65 
66   /**
67    * Sets the current position.
68    *
69    * @param position The current position to show, in milliseconds.
70    */
setPosition(long position)71   void setPosition(long position);
72 
73   /**
74    * Sets the buffered position.
75    *
76    * @param bufferedPosition The current buffered position to show, in milliseconds.
77    */
setBufferedPosition(long bufferedPosition)78   void setBufferedPosition(long bufferedPosition);
79 
80   /**
81    * Sets the duration.
82    *
83    * @param duration The duration to show, in milliseconds.
84    */
setDuration(long duration)85   void setDuration(long duration);
86 
87   /**
88    * Returns the preferred delay in milliseconds of media time after which the time bar position
89    * should be updated.
90    *
91    * @return Preferred delay, in milliseconds of media time.
92    */
getPreferredUpdateDelay()93   long getPreferredUpdateDelay();
94 
95   /**
96    * Sets the times of ad groups and whether each ad group has been played.
97    *
98    * @param adGroupTimesMs An array where the first {@code adGroupCount} elements are the times of
99    *     ad groups in milliseconds. May be {@code null} if there are no ad groups.
100    * @param playedAdGroups An array where the first {@code adGroupCount} elements indicate whether
101    *     the corresponding ad groups have been played. May be {@code null} if there are no ad
102    *     groups.
103    * @param adGroupCount The number of ad groups.
104    */
setAdGroupTimesMs(@ullable long[] adGroupTimesMs, @Nullable boolean[] playedAdGroups, int adGroupCount)105   void setAdGroupTimesMs(@Nullable long[] adGroupTimesMs, @Nullable boolean[] playedAdGroups,
106       int adGroupCount);
107 
108   /**
109    * Listener for scrubbing events.
110    */
111   interface OnScrubListener {
112 
113     /**
114      * Called when the user starts moving the scrubber.
115      *
116      * @param timeBar The time bar.
117      * @param position The scrub position in milliseconds.
118      */
onScrubStart(TimeBar timeBar, long position)119     void onScrubStart(TimeBar timeBar, long position);
120 
121     /**
122      * Called when the user moves the scrubber.
123      *
124      * @param timeBar The time bar.
125      * @param position The scrub position in milliseconds.
126      */
onScrubMove(TimeBar timeBar, long position)127     void onScrubMove(TimeBar timeBar, long position);
128 
129     /**
130      * Called when the user stops moving the scrubber.
131      *
132      * @param timeBar The time bar.
133      * @param position The scrub position in milliseconds.
134      * @param canceled Whether scrubbing was canceled.
135      */
onScrubStop(TimeBar timeBar, long position, boolean canceled)136     void onScrubStop(TimeBar timeBar, long position, boolean canceled);
137   }
138 
139 }
140