• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
17 
18 import android.content.Context;
19 import android.os.Looper;
20 import android.view.Surface;
21 import android.view.SurfaceHolder;
22 import android.view.SurfaceView;
23 import android.view.TextureView;
24 import androidx.annotation.IntDef;
25 import androidx.annotation.Nullable;
26 import com.google.android.exoplayer2.C.VideoScalingMode;
27 import com.google.android.exoplayer2.audio.AudioAttributes;
28 import com.google.android.exoplayer2.audio.AudioListener;
29 import com.google.android.exoplayer2.audio.AuxEffectInfo;
30 import com.google.android.exoplayer2.device.DeviceInfo;
31 import com.google.android.exoplayer2.device.DeviceListener;
32 import com.google.android.exoplayer2.metadata.MetadataOutput;
33 import com.google.android.exoplayer2.source.TrackGroupArray;
34 import com.google.android.exoplayer2.text.TextOutput;
35 import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
36 import com.google.android.exoplayer2.util.Util;
37 import com.google.android.exoplayer2.video.VideoDecoderOutputBufferRenderer;
38 import com.google.android.exoplayer2.video.VideoFrameMetadataListener;
39 import com.google.android.exoplayer2.video.VideoListener;
40 import com.google.android.exoplayer2.video.spherical.CameraMotionListener;
41 import java.lang.annotation.Documented;
42 import java.lang.annotation.Retention;
43 import java.lang.annotation.RetentionPolicy;
44 import java.util.List;
45 
46 /**
47  * A media player interface defining traditional high-level functionality, such as the ability to
48  * play, pause, seek and query properties of the currently playing media.
49  *
50  * <p>Some important properties of media players that implement this interface are:
51  *
52  * <ul>
53  *   <li>They can provide a {@link Timeline} representing the structure of the media being played,
54  *       which can be obtained by calling {@link #getCurrentTimeline()}.
55  *   <li>They can provide a {@link TrackGroupArray} defining the currently available tracks, which
56  *       can be obtained by calling {@link #getCurrentTrackGroups()}.
57  *   <li>They contain a number of renderers, each of which is able to render tracks of a single type
58  *       (e.g. audio, video or text). The number of renderers and their respective track types can
59  *       be obtained by calling {@link #getRendererCount()} and {@link #getRendererType(int)}.
60  *   <li>They can provide a {@link TrackSelectionArray} defining which of the currently available
61  *       tracks are selected to be rendered by each renderer. This can be obtained by calling {@link
62  *       #getCurrentTrackSelections()}}.
63  * </ul>
64  */
65 public interface Player {
66 
67   /** The audio component of a {@link Player}. */
68   interface AudioComponent {
69 
70     /**
71      * Adds a listener to receive audio events.
72      *
73      * @param listener The listener to register.
74      */
addAudioListener(AudioListener listener)75     void addAudioListener(AudioListener listener);
76 
77     /**
78      * Removes a listener of audio events.
79      *
80      * @param listener The listener to unregister.
81      */
removeAudioListener(AudioListener listener)82     void removeAudioListener(AudioListener listener);
83 
84     /**
85      * Sets the attributes for audio playback, used by the underlying audio track. If not set, the
86      * default audio attributes will be used. They are suitable for general media playback.
87      *
88      * <p>Setting the audio attributes during playback may introduce a short gap in audio output as
89      * the audio track is recreated. A new audio session id will also be generated.
90      *
91      * <p>If tunneling is enabled by the track selector, the specified audio attributes will be
92      * ignored, but they will take effect if audio is later played without tunneling.
93      *
94      * <p>If the device is running a build before platform API version 21, audio attributes cannot
95      * be set directly on the underlying audio track. In this case, the usage will be mapped onto an
96      * equivalent stream type using {@link Util#getStreamTypeForAudioUsage(int)}.
97      *
98      * @param audioAttributes The attributes to use for audio playback.
99      * @deprecated Use {@link AudioComponent#setAudioAttributes(AudioAttributes, boolean)}.
100      */
101     @Deprecated
setAudioAttributes(AudioAttributes audioAttributes)102     void setAudioAttributes(AudioAttributes audioAttributes);
103 
104     /**
105      * Sets the attributes for audio playback, used by the underlying audio track. If not set, the
106      * default audio attributes will be used. They are suitable for general media playback.
107      *
108      * <p>Setting the audio attributes during playback may introduce a short gap in audio output as
109      * the audio track is recreated. A new audio session id will also be generated.
110      *
111      * <p>If tunneling is enabled by the track selector, the specified audio attributes will be
112      * ignored, but they will take effect if audio is later played without tunneling.
113      *
114      * <p>If the device is running a build before platform API version 21, audio attributes cannot
115      * be set directly on the underlying audio track. In this case, the usage will be mapped onto an
116      * equivalent stream type using {@link Util#getStreamTypeForAudioUsage(int)}.
117      *
118      * <p>If audio focus should be handled, the {@link AudioAttributes#usage} must be {@link
119      * C#USAGE_MEDIA} or {@link C#USAGE_GAME}. Other usages will throw an {@link
120      * IllegalArgumentException}.
121      *
122      * @param audioAttributes The attributes to use for audio playback.
123      * @param handleAudioFocus True if the player should handle audio focus, false otherwise.
124      */
setAudioAttributes(AudioAttributes audioAttributes, boolean handleAudioFocus)125     void setAudioAttributes(AudioAttributes audioAttributes, boolean handleAudioFocus);
126 
127     /** Returns the attributes for audio playback. */
getAudioAttributes()128     AudioAttributes getAudioAttributes();
129 
130     /**
131      * Sets the ID of the audio session to attach to the underlying {@link
132      * android.media.AudioTrack}.
133      *
134      * <p>The audio session ID can be generated using {@link C#generateAudioSessionIdV21(Context)}
135      * for API 21+.
136      *
137      * @param audioSessionId The audio session ID, or {@link C#AUDIO_SESSION_ID_UNSET} if it should
138      *     be generated by the framework.
139      */
setAudioSessionId(int audioSessionId)140     void setAudioSessionId(int audioSessionId);
141 
142     /** Returns the audio session identifier, or {@link C#AUDIO_SESSION_ID_UNSET} if not set. */
getAudioSessionId()143     int getAudioSessionId();
144 
145     /** Sets information on an auxiliary audio effect to attach to the underlying audio track. */
setAuxEffectInfo(AuxEffectInfo auxEffectInfo)146     void setAuxEffectInfo(AuxEffectInfo auxEffectInfo);
147 
148     /** Detaches any previously attached auxiliary audio effect from the underlying audio track. */
clearAuxEffectInfo()149     void clearAuxEffectInfo();
150 
151     /**
152      * Sets the audio volume, with 0 being silence and 1 being unity gain.
153      *
154      * @param audioVolume The audio volume.
155      */
setVolume(float audioVolume)156     void setVolume(float audioVolume);
157 
158     /** Returns the audio volume, with 0 being silence and 1 being unity gain. */
getVolume()159     float getVolume();
160 
161     /**
162      * Sets whether skipping silences in the audio stream is enabled.
163      *
164      * @param skipSilenceEnabled Whether skipping silences in the audio stream is enabled.
165      */
setSkipSilenceEnabled(boolean skipSilenceEnabled)166     void setSkipSilenceEnabled(boolean skipSilenceEnabled);
167 
168     /** Returns whether skipping silences in the audio stream is enabled. */
getSkipSilenceEnabled()169     boolean getSkipSilenceEnabled();
170   }
171 
172   /** The video component of a {@link Player}. */
173   interface VideoComponent {
174 
175     /**
176      * Sets the {@link VideoScalingMode}.
177      *
178      * @param videoScalingMode The {@link VideoScalingMode}.
179      */
setVideoScalingMode(@ideoScalingMode int videoScalingMode)180     void setVideoScalingMode(@VideoScalingMode int videoScalingMode);
181 
182     /** Returns the {@link VideoScalingMode}. */
183     @VideoScalingMode
getVideoScalingMode()184     int getVideoScalingMode();
185 
186     /**
187      * Adds a listener to receive video events.
188      *
189      * @param listener The listener to register.
190      */
addVideoListener(VideoListener listener)191     void addVideoListener(VideoListener listener);
192 
193     /**
194      * Removes a listener of video events.
195      *
196      * @param listener The listener to unregister.
197      */
removeVideoListener(VideoListener listener)198     void removeVideoListener(VideoListener listener);
199 
200     /**
201      * Sets a listener to receive video frame metadata events.
202      *
203      * <p>This method is intended to be called by the same component that sets the {@link Surface}
204      * onto which video will be rendered. If using ExoPlayer's standard UI components, this method
205      * should not be called directly from application code.
206      *
207      * @param listener The listener.
208      */
setVideoFrameMetadataListener(VideoFrameMetadataListener listener)209     void setVideoFrameMetadataListener(VideoFrameMetadataListener listener);
210 
211     /**
212      * Clears the listener which receives video frame metadata events if it matches the one passed.
213      * Else does nothing.
214      *
215      * @param listener The listener to clear.
216      */
clearVideoFrameMetadataListener(VideoFrameMetadataListener listener)217     void clearVideoFrameMetadataListener(VideoFrameMetadataListener listener);
218 
219     /**
220      * Sets a listener of camera motion events.
221      *
222      * @param listener The listener.
223      */
setCameraMotionListener(CameraMotionListener listener)224     void setCameraMotionListener(CameraMotionListener listener);
225 
226     /**
227      * Clears the listener which receives camera motion events if it matches the one passed. Else
228      * does nothing.
229      *
230      * @param listener The listener to clear.
231      */
clearCameraMotionListener(CameraMotionListener listener)232     void clearCameraMotionListener(CameraMotionListener listener);
233 
234     /**
235      * Clears any {@link Surface}, {@link SurfaceHolder}, {@link SurfaceView} or {@link TextureView}
236      * currently set on the player.
237      */
clearVideoSurface()238     void clearVideoSurface();
239 
240     /**
241      * Clears the {@link Surface} onto which video is being rendered if it matches the one passed.
242      * Else does nothing.
243      *
244      * @param surface The surface to clear.
245      */
clearVideoSurface(@ullable Surface surface)246     void clearVideoSurface(@Nullable Surface surface);
247 
248     /**
249      * Sets the {@link Surface} onto which video will be rendered. The caller is responsible for
250      * tracking the lifecycle of the surface, and must clear the surface by calling {@code
251      * setVideoSurface(null)} if the surface is destroyed.
252      *
253      * <p>If the surface is held by a {@link SurfaceView}, {@link TextureView} or {@link
254      * SurfaceHolder} then it's recommended to use {@link #setVideoSurfaceView(SurfaceView)}, {@link
255      * #setVideoTextureView(TextureView)} or {@link #setVideoSurfaceHolder(SurfaceHolder)} rather
256      * than this method, since passing the holder allows the player to track the lifecycle of the
257      * surface automatically.
258      *
259      * @param surface The {@link Surface}.
260      */
setVideoSurface(@ullable Surface surface)261     void setVideoSurface(@Nullable Surface surface);
262 
263     /**
264      * Sets the {@link SurfaceHolder} that holds the {@link Surface} onto which video will be
265      * rendered. The player will track the lifecycle of the surface automatically.
266      *
267      * @param surfaceHolder The surface holder.
268      */
setVideoSurfaceHolder(@ullable SurfaceHolder surfaceHolder)269     void setVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder);
270 
271     /**
272      * Clears the {@link SurfaceHolder} that holds the {@link Surface} onto which video is being
273      * rendered if it matches the one passed. Else does nothing.
274      *
275      * @param surfaceHolder The surface holder to clear.
276      */
clearVideoSurfaceHolder(@ullable SurfaceHolder surfaceHolder)277     void clearVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder);
278 
279     /**
280      * Sets the {@link SurfaceView} onto which video will be rendered. The player will track the
281      * lifecycle of the surface automatically.
282      *
283      * @param surfaceView The surface view.
284      */
setVideoSurfaceView(@ullable SurfaceView surfaceView)285     void setVideoSurfaceView(@Nullable SurfaceView surfaceView);
286 
287     /**
288      * Clears the {@link SurfaceView} onto which video is being rendered if it matches the one
289      * passed. Else does nothing.
290      *
291      * @param surfaceView The texture view to clear.
292      */
clearVideoSurfaceView(@ullable SurfaceView surfaceView)293     void clearVideoSurfaceView(@Nullable SurfaceView surfaceView);
294 
295     /**
296      * Sets the {@link TextureView} onto which video will be rendered. The player will track the
297      * lifecycle of the surface automatically.
298      *
299      * @param textureView The texture view.
300      */
setVideoTextureView(@ullable TextureView textureView)301     void setVideoTextureView(@Nullable TextureView textureView);
302 
303     /**
304      * Clears the {@link TextureView} onto which video is being rendered if it matches the one
305      * passed. Else does nothing.
306      *
307      * @param textureView The texture view to clear.
308      */
clearVideoTextureView(@ullable TextureView textureView)309     void clearVideoTextureView(@Nullable TextureView textureView);
310 
311     /**
312      * Sets the video decoder output buffer renderer. This is intended for use only with extension
313      * renderers that accept {@link C#MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER}. For most use
314      * cases, an output surface or view should be passed via {@link #setVideoSurface(Surface)} or
315      * {@link #setVideoSurfaceView(SurfaceView)} instead.
316      *
317      * @param videoDecoderOutputBufferRenderer The video decoder output buffer renderer, or {@code
318      *     null} to clear the output buffer renderer.
319      */
setVideoDecoderOutputBufferRenderer( @ullable VideoDecoderOutputBufferRenderer videoDecoderOutputBufferRenderer)320     void setVideoDecoderOutputBufferRenderer(
321         @Nullable VideoDecoderOutputBufferRenderer videoDecoderOutputBufferRenderer);
322 
323     /** Clears the video decoder output buffer renderer. */
clearVideoDecoderOutputBufferRenderer()324     void clearVideoDecoderOutputBufferRenderer();
325 
326     /**
327      * Clears the video decoder output buffer renderer if it matches the one passed. Else does
328      * nothing.
329      *
330      * @param videoDecoderOutputBufferRenderer The video decoder output buffer renderer to clear.
331      */
clearVideoDecoderOutputBufferRenderer( @ullable VideoDecoderOutputBufferRenderer videoDecoderOutputBufferRenderer)332     void clearVideoDecoderOutputBufferRenderer(
333         @Nullable VideoDecoderOutputBufferRenderer videoDecoderOutputBufferRenderer);
334   }
335 
336   /** The text component of a {@link Player}. */
337   interface TextComponent {
338 
339     /**
340      * Registers an output to receive text events.
341      *
342      * @param listener The output to register.
343      */
addTextOutput(TextOutput listener)344     void addTextOutput(TextOutput listener);
345 
346     /**
347      * Removes a text output.
348      *
349      * @param listener The output to remove.
350      */
removeTextOutput(TextOutput listener)351     void removeTextOutput(TextOutput listener);
352   }
353 
354   /** The metadata component of a {@link Player}. */
355   interface MetadataComponent {
356 
357     /**
358      * Adds a {@link MetadataOutput} to receive metadata.
359      *
360      * @param output The output to register.
361      */
addMetadataOutput(MetadataOutput output)362     void addMetadataOutput(MetadataOutput output);
363 
364     /**
365      * Removes a {@link MetadataOutput}.
366      *
367      * @param output The output to remove.
368      */
removeMetadataOutput(MetadataOutput output)369     void removeMetadataOutput(MetadataOutput output);
370   }
371 
372   /** The device component of a {@link Player}. */
373   // Note: It's mostly from the androidx.media.VolumeProviderCompat and
374   //  androidx.media.MediaControllerCompat.PlaybackInfo.
375   interface DeviceComponent {
376 
377     /** Adds a listener to receive device events. */
addDeviceListener(DeviceListener listener)378     void addDeviceListener(DeviceListener listener);
379 
380     /** Removes a listener of device events. */
removeDeviceListener(DeviceListener listener)381     void removeDeviceListener(DeviceListener listener);
382 
383     /** Gets the device information. */
getDeviceInfo()384     DeviceInfo getDeviceInfo();
385 
386     /**
387      * Gets the current volume of the device.
388      *
389      * <p>For devices with {@link DeviceInfo#PLAYBACK_TYPE_LOCAL local playback}, the volume
390      * returned by this method varies according to the current {@link C.StreamType stream type}. The
391      * stream type is determined by {@link AudioAttributes#usage} which can be converted to stream
392      * type with {@link Util#getStreamTypeForAudioUsage(int)}. The audio attributes can be set to
393      * the player by calling {@link AudioComponent#setAudioAttributes}.
394      *
395      * <p>For devices with {@link DeviceInfo#PLAYBACK_TYPE_REMOTE remote playback}, the volume of
396      * the remote device is returned.
397      */
getDeviceVolume()398     int getDeviceVolume();
399 
400     /** Gets whether the device is muted or not. */
isDeviceMuted()401     boolean isDeviceMuted();
402 
403     /**
404      * Sets the volume of the device.
405      *
406      * @param volume The volume to set.
407      */
setDeviceVolume(int volume)408     void setDeviceVolume(int volume);
409 
410     /** Increases the volume of the device. */
increaseDeviceVolume()411     void increaseDeviceVolume();
412 
413     /** Decreases the volume of the device. */
decreaseDeviceVolume()414     void decreaseDeviceVolume();
415 
416     /** Sets the mute state of the device. */
setDeviceMuted(boolean muted)417     void setDeviceMuted(boolean muted);
418   }
419 
420   /**
421    * Listener of changes in player state. All methods have no-op default implementations to allow
422    * selective overrides.
423    */
424   interface EventListener {
425 
426     /**
427      * Called when the timeline has been refreshed.
428      *
429      * <p>Note that if the timeline has changed then a position discontinuity may also have
430      * occurred. For example, the current period index may have changed as a result of periods being
431      * added or removed from the timeline. This will <em>not</em> be reported via a separate call to
432      * {@link #onPositionDiscontinuity(int)}.
433      *
434      * @param timeline The latest timeline. Never null, but may be empty.
435      * @param reason The {@link TimelineChangeReason} responsible for this timeline change.
436      */
437     @SuppressWarnings("deprecation")
onTimelineChanged(Timeline timeline, @TimelineChangeReason int reason)438     default void onTimelineChanged(Timeline timeline, @TimelineChangeReason int reason) {
439       Object manifest = null;
440       if (timeline.getWindowCount() == 1) {
441         // Legacy behavior was to report the manifest for single window timelines only.
442         Timeline.Window window = new Timeline.Window();
443         manifest = timeline.getWindow(0, window).manifest;
444       }
445       // Call deprecated version.
446       onTimelineChanged(timeline, manifest, reason);
447     }
448 
449     /**
450      * Called when the timeline and/or manifest has been refreshed.
451      *
452      * <p>Note that if the timeline has changed then a position discontinuity may also have
453      * occurred. For example, the current period index may have changed as a result of periods being
454      * added or removed from the timeline. This will <em>not</em> be reported via a separate call to
455      * {@link #onPositionDiscontinuity(int)}.
456      *
457      * @param timeline The latest timeline. Never null, but may be empty.
458      * @param manifest The latest manifest in case the timeline has a single window only. Always
459      *     null if the timeline has more than a single window.
460      * @param reason The {@link TimelineChangeReason} responsible for this timeline change.
461      * @deprecated Use {@link #onTimelineChanged(Timeline, int)} instead. The manifest can be
462      *     accessed by using {@link #getCurrentManifest()} or {@code timeline.getWindow(windowIndex,
463      *     window).manifest} for a given window index.
464      */
465     @Deprecated
onTimelineChanged( Timeline timeline, @Nullable Object manifest, @TimelineChangeReason int reason)466     default void onTimelineChanged(
467         Timeline timeline, @Nullable Object manifest, @TimelineChangeReason int reason) {}
468 
469     /**
470      * Called when the available or selected tracks change.
471      *
472      * @param trackGroups The available tracks. Never null, but may be of length zero.
473      * @param trackSelections The track selections for each renderer. Never null and always of
474      *     length {@link #getRendererCount()}, but may contain null elements.
475      */
onTracksChanged( TrackGroupArray trackGroups, TrackSelectionArray trackSelections)476     default void onTracksChanged(
477         TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {}
478 
479     /**
480      * Called when the player starts or stops loading the source.
481      *
482      * @param isLoading Whether the source is currently being loaded.
483      */
484     @SuppressWarnings("deprecation")
onIsLoadingChanged(boolean isLoading)485     default void onIsLoadingChanged(boolean isLoading) {
486       onLoadingChanged(isLoading);
487     }
488 
489     /** @deprecated Use {@link #onIsLoadingChanged(boolean)} instead. */
490     @Deprecated
onLoadingChanged(boolean isLoading)491     default void onLoadingChanged(boolean isLoading) {}
492 
493     /**
494      * @deprecated Use {@link #onPlaybackStateChanged(int)} and {@link
495      *     #onPlayWhenReadyChanged(boolean, int)} instead.
496      */
497     @Deprecated
onPlayerStateChanged(boolean playWhenReady, @State int playbackState)498     default void onPlayerStateChanged(boolean playWhenReady, @State int playbackState) {}
499 
500     /**
501      * Called when the value returned from {@link #getPlaybackState()} changes.
502      *
503      * @param state The new playback {@link State state}.
504      */
onPlaybackStateChanged(@tate int state)505     default void onPlaybackStateChanged(@State int state) {}
506 
507     /**
508      * Called when the value returned from {@link #getPlayWhenReady()} changes.
509      *
510      * @param playWhenReady Whether playback will proceed when ready.
511      * @param reason The {@link PlayWhenReadyChangeReason reason} for the change.
512      */
onPlayWhenReadyChanged( boolean playWhenReady, @PlayWhenReadyChangeReason int reason)513     default void onPlayWhenReadyChanged(
514         boolean playWhenReady, @PlayWhenReadyChangeReason int reason) {}
515 
516     /**
517      * Called when the value returned from {@link #getPlaybackSuppressionReason()} changes.
518      *
519      * @param playbackSuppressionReason The current {@link PlaybackSuppressionReason}.
520      */
onPlaybackSuppressionReasonChanged( @laybackSuppressionReason int playbackSuppressionReason)521     default void onPlaybackSuppressionReasonChanged(
522         @PlaybackSuppressionReason int playbackSuppressionReason) {}
523 
524     /**
525      * Called when the value of {@link #isPlaying()} changes.
526      *
527      * @param isPlaying Whether the player is playing.
528      */
onIsPlayingChanged(boolean isPlaying)529     default void onIsPlayingChanged(boolean isPlaying) {}
530 
531     /**
532      * Called when the value of {@link #getRepeatMode()} changes.
533      *
534      * @param repeatMode The {@link RepeatMode} used for playback.
535      */
onRepeatModeChanged(@epeatMode int repeatMode)536     default void onRepeatModeChanged(@RepeatMode int repeatMode) {}
537 
538     /**
539      * Called when the value of {@link #getShuffleModeEnabled()} changes.
540      *
541      * @param shuffleModeEnabled Whether shuffling of windows is enabled.
542      */
onShuffleModeEnabledChanged(boolean shuffleModeEnabled)543     default void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {}
544 
545     /**
546      * Called when an error occurs. The playback state will transition to {@link #STATE_IDLE}
547      * immediately after this method is called. The player instance can still be used, and {@link
548      * #release()} must still be called on the player should it no longer be required.
549      *
550      * @param error The error.
551      */
onPlayerError(ExoPlaybackException error)552     default void onPlayerError(ExoPlaybackException error) {}
553 
554     /**
555      * Called when a position discontinuity occurs without a change to the timeline. A position
556      * discontinuity occurs when the current window or period index changes (as a result of playback
557      * transitioning from one period in the timeline to the next), or when the playback position
558      * jumps within the period currently being played (as a result of a seek being performed, or
559      * when the source introduces a discontinuity internally).
560      *
561      * <p>When a position discontinuity occurs as a result of a change to the timeline this method
562      * is <em>not</em> called. {@link #onTimelineChanged(Timeline, int)} is called in this case.
563      *
564      * @param reason The {@link DiscontinuityReason} responsible for the discontinuity.
565      */
onPositionDiscontinuity(@iscontinuityReason int reason)566     default void onPositionDiscontinuity(@DiscontinuityReason int reason) {}
567 
568     /**
569      * @deprecated Use {@link #onPlaybackSpeedChanged(float)} and {@link
570      *     AudioListener#onSkipSilenceEnabledChanged(boolean)} instead.
571      */
572     @SuppressWarnings("deprecation")
573     @Deprecated
onPlaybackParametersChanged(PlaybackParameters playbackParameters)574     default void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {}
575 
576     /**
577      * Called when the current playback speed changes. The normal playback speed is 1. The speed may
578      * change due to a call to {@link #setPlaybackSpeed(float)}, or the player itself may change it
579      * (for example, if audio playback switches to passthrough mode, where speed adjustment is no
580      * longer possible).
581      */
onPlaybackSpeedChanged(float playbackSpeed)582     default void onPlaybackSpeedChanged(float playbackSpeed) {}
583 
584     /**
585      * @deprecated Seeks are processed without delay. Listen to {@link
586      *     #onPositionDiscontinuity(int)} with reason {@link #DISCONTINUITY_REASON_SEEK} instead.
587      */
588     @Deprecated
onSeekProcessed()589     default void onSeekProcessed() {}
590   }
591 
592   /**
593    * @deprecated Use {@link EventListener} interface directly for selective overrides as all methods
594    *     are implemented as no-op default methods.
595    */
596   @Deprecated
597   abstract class DefaultEventListener implements EventListener {
598 
599     @Override
onTimelineChanged(Timeline timeline, @TimelineChangeReason int reason)600     public void onTimelineChanged(Timeline timeline, @TimelineChangeReason int reason) {
601       Object manifest = null;
602       if (timeline.getWindowCount() == 1) {
603         // Legacy behavior was to report the manifest for single window timelines only.
604         Timeline.Window window = new Timeline.Window();
605         manifest = timeline.getWindow(0, window).manifest;
606       }
607       // Call deprecated version.
608       onTimelineChanged(timeline, manifest, reason);
609     }
610 
611     @Override
612     @SuppressWarnings("deprecation")
onTimelineChanged( Timeline timeline, @Nullable Object manifest, @TimelineChangeReason int reason)613     public void onTimelineChanged(
614         Timeline timeline, @Nullable Object manifest, @TimelineChangeReason int reason) {
615       // Call deprecated version. Otherwise, do nothing.
616       onTimelineChanged(timeline, manifest);
617     }
618 
619     /** @deprecated Use {@link EventListener#onTimelineChanged(Timeline, int)} instead. */
620     @Deprecated
onTimelineChanged(Timeline timeline, @Nullable Object manifest)621     public void onTimelineChanged(Timeline timeline, @Nullable Object manifest) {
622       // Do nothing.
623     }
624   }
625 
626   /**
627    * Playback state. One of {@link #STATE_IDLE}, {@link #STATE_BUFFERING}, {@link #STATE_READY} or
628    * {@link #STATE_ENDED}.
629    */
630   @Documented
631   @Retention(RetentionPolicy.SOURCE)
632   @IntDef({STATE_IDLE, STATE_BUFFERING, STATE_READY, STATE_ENDED})
633   @interface State {}
634   /**
635    * The player does not have any media to play.
636    */
637   int STATE_IDLE = 1;
638   /**
639    * The player is not able to immediately play from its current position. This state typically
640    * occurs when more data needs to be loaded.
641    */
642   int STATE_BUFFERING = 2;
643   /**
644    * The player is able to immediately play from its current position. The player will be playing if
645    * {@link #getPlayWhenReady()} is true, and paused otherwise.
646    */
647   int STATE_READY = 3;
648   /**
649    * The player has finished playing the media.
650    */
651   int STATE_ENDED = 4;
652 
653   /**
654    * Reasons for {@link #getPlayWhenReady() playWhenReady} changes. One of {@link
655    * #PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST}, {@link
656    * #PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS}, {@link
657    * #PLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY}, {@link
658    * #PLAY_WHEN_READY_CHANGE_REASON_REMOTE} or {@link
659    * #PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM}.
660    */
661   @Documented
662   @Retention(RetentionPolicy.SOURCE)
663   @IntDef({
664     PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST,
665     PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS,
666     PLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY,
667     PLAY_WHEN_READY_CHANGE_REASON_REMOTE,
668     PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM
669   })
670   @interface PlayWhenReadyChangeReason {}
671   /** Playback has been started or paused by a call to {@link #setPlayWhenReady(boolean)}. */
672   int PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST = 1;
673   /** Playback has been paused because of a loss of audio focus. */
674   int PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS = 2;
675   /** Playback has been paused to avoid becoming noisy. */
676   int PLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY = 3;
677   /** Playback has been started or paused because of a remote change. */
678   int PLAY_WHEN_READY_CHANGE_REASON_REMOTE = 4;
679   /** Playback has been paused at the end of a media item. */
680   int PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM = 5;
681 
682   /**
683    * Reason why playback is suppressed even though {@link #getPlayWhenReady()} is {@code true}. One
684    * of {@link #PLAYBACK_SUPPRESSION_REASON_NONE} or {@link
685    * #PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS}.
686    */
687   @Documented
688   @Retention(RetentionPolicy.SOURCE)
689   @IntDef({
690     PLAYBACK_SUPPRESSION_REASON_NONE,
691     PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS
692   })
693   @interface PlaybackSuppressionReason {}
694   /** Playback is not suppressed. */
695   int PLAYBACK_SUPPRESSION_REASON_NONE = 0;
696   /** Playback is suppressed due to transient audio focus loss. */
697   int PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS = 1;
698 
699   /**
700    * Repeat modes for playback. One of {@link #REPEAT_MODE_OFF}, {@link #REPEAT_MODE_ONE} or {@link
701    * #REPEAT_MODE_ALL}.
702    */
703   @Documented
704   @Retention(RetentionPolicy.SOURCE)
705   @IntDef({REPEAT_MODE_OFF, REPEAT_MODE_ONE, REPEAT_MODE_ALL})
706   @interface RepeatMode {}
707   /**
708    * Normal playback without repetition.
709    */
710   int REPEAT_MODE_OFF = 0;
711   /**
712    * "Repeat One" mode to repeat the currently playing window infinitely.
713    */
714   int REPEAT_MODE_ONE = 1;
715   /**
716    * "Repeat All" mode to repeat the entire timeline infinitely.
717    */
718   int REPEAT_MODE_ALL = 2;
719 
720   /**
721    * Reasons for position discontinuities. One of {@link #DISCONTINUITY_REASON_PERIOD_TRANSITION},
722    * {@link #DISCONTINUITY_REASON_SEEK}, {@link #DISCONTINUITY_REASON_SEEK_ADJUSTMENT}, {@link
723    * #DISCONTINUITY_REASON_AD_INSERTION} or {@link #DISCONTINUITY_REASON_INTERNAL}.
724    */
725   @Documented
726   @Retention(RetentionPolicy.SOURCE)
727   @IntDef({
728     DISCONTINUITY_REASON_PERIOD_TRANSITION,
729     DISCONTINUITY_REASON_SEEK,
730     DISCONTINUITY_REASON_SEEK_ADJUSTMENT,
731     DISCONTINUITY_REASON_AD_INSERTION,
732     DISCONTINUITY_REASON_INTERNAL
733   })
734   @interface DiscontinuityReason {}
735   /**
736    * Automatic playback transition from one period in the timeline to the next. The period index may
737    * be the same as it was before the discontinuity in case the current period is repeated.
738    */
739   int DISCONTINUITY_REASON_PERIOD_TRANSITION = 0;
740   /** Seek within the current period or to another period. */
741   int DISCONTINUITY_REASON_SEEK = 1;
742   /**
743    * Seek adjustment due to being unable to seek to the requested position or because the seek was
744    * permitted to be inexact.
745    */
746   int DISCONTINUITY_REASON_SEEK_ADJUSTMENT = 2;
747   /** Discontinuity to or from an ad within one period in the timeline. */
748   int DISCONTINUITY_REASON_AD_INSERTION = 3;
749   /** Discontinuity introduced internally by the source. */
750   int DISCONTINUITY_REASON_INTERNAL = 4;
751 
752   /**
753    * Reasons for timeline changes. One of {@link #TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED} or {@link
754    * #TIMELINE_CHANGE_REASON_SOURCE_UPDATE}.
755    */
756   @Documented
757   @Retention(RetentionPolicy.SOURCE)
758   @IntDef({TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, TIMELINE_CHANGE_REASON_SOURCE_UPDATE})
759   @interface TimelineChangeReason {}
760   /** Timeline changed as a result of a change of the playlist items or the order of the items. */
761   int TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED = 0;
762   /** Timeline changed as a result of a dynamic update introduced by the played media. */
763   int TIMELINE_CHANGE_REASON_SOURCE_UPDATE = 1;
764 
765   /** The default playback speed. */
766   float DEFAULT_PLAYBACK_SPEED = 1.0f;
767 
768   /** Returns the component of this player for audio output, or null if audio is not supported. */
769   @Nullable
getAudioComponent()770   AudioComponent getAudioComponent();
771 
772   /** Returns the component of this player for video output, or null if video is not supported. */
773   @Nullable
getVideoComponent()774   VideoComponent getVideoComponent();
775 
776   /** Returns the component of this player for text output, or null if text is not supported. */
777   @Nullable
getTextComponent()778   TextComponent getTextComponent();
779 
780   /**
781    * Returns the component of this player for metadata output, or null if metadata is not supported.
782    */
783   @Nullable
getMetadataComponent()784   MetadataComponent getMetadataComponent();
785 
786   /** Returns the component of this player for playback device, or null if it's not supported. */
787   @Nullable
getDeviceComponent()788   DeviceComponent getDeviceComponent();
789 
790   /**
791    * Returns the {@link Looper} associated with the application thread that's used to access the
792    * player and on which player events are received.
793    */
getApplicationLooper()794   Looper getApplicationLooper();
795 
796   /**
797    * Register a listener to receive events from the player. The listener's methods will be called on
798    * the thread that was used to construct the player. However, if the thread used to construct the
799    * player does not have a {@link Looper}, then the listener will be called on the main thread.
800    *
801    * @param listener The listener to register.
802    */
addListener(EventListener listener)803   void addListener(EventListener listener);
804 
805   /**
806    * Unregister a listener. The listener will no longer receive events from the player.
807    *
808    * @param listener The listener to unregister.
809    */
removeListener(EventListener listener)810   void removeListener(EventListener listener);
811 
812   /**
813    * Clears the playlist, adds the specified {@link MediaItem MediaItems} and resets the position to
814    * the default position.
815    *
816    * @param mediaItems The new {@link MediaItem MediaItems}.
817    */
setMediaItems(List<MediaItem> mediaItems)818   void setMediaItems(List<MediaItem> mediaItems);
819 
820   /**
821    * Clears the playlist and adds the specified {@link MediaItem MediaItems}.
822    *
823    * @param mediaItems The new {@link MediaItem MediaItems}.
824    * @param resetPosition Whether the playback position should be reset to the default position in
825    *     the first {@link Timeline.Window}. If false, playback will start from the position defined
826    *     by {@link #getCurrentWindowIndex()} and {@link #getCurrentPosition()}.
827    */
setMediaItems(List<MediaItem> mediaItems, boolean resetPosition)828   void setMediaItems(List<MediaItem> mediaItems, boolean resetPosition);
829 
830   /**
831    * Clears the playlist and adds the specified {@link MediaItem MediaItems}.
832    *
833    * @param mediaItems The new {@link MediaItem MediaItems}.
834    * @param startWindowIndex The window index to start playback from. If {@link C#INDEX_UNSET} is
835    *     passed, the current position is not reset.
836    * @param startPositionMs The position in milliseconds to start playback from. If {@link
837    *     C#TIME_UNSET} is passed, the default position of the given window is used. In any case, if
838    *     {@code startWindowIndex} is set to {@link C#INDEX_UNSET}, this parameter is ignored and the
839    *     position is not reset at all.
840    */
setMediaItems(List<MediaItem> mediaItems, int startWindowIndex, long startPositionMs)841   void setMediaItems(List<MediaItem> mediaItems, int startWindowIndex, long startPositionMs);
842 
843   /**
844    * Clears the playlist, adds the specified {@link MediaItem} and resets the position to the
845    * default position.
846    *
847    * @param mediaItem The new {@link MediaItem}.
848    */
setMediaItem(MediaItem mediaItem)849   void setMediaItem(MediaItem mediaItem);
850 
851   /**
852    * Clears the playlist and adds the specified {@link MediaItem}.
853    *
854    * @param mediaItem The new {@link MediaItem}.
855    * @param startPositionMs The position in milliseconds to start playback from.
856    */
setMediaItem(MediaItem mediaItem, long startPositionMs)857   void setMediaItem(MediaItem mediaItem, long startPositionMs);
858 
859   /**
860    * Clears the playlist and adds the specified {@link MediaItem}.
861    *
862    * @param mediaItem The new {@link MediaItem}.
863    * @param resetPosition Whether the playback position should be reset to the default position. If
864    *     false, playback will start from the position defined by {@link #getCurrentWindowIndex()}
865    *     and {@link #getCurrentPosition()}.
866    */
setMediaItem(MediaItem mediaItem, boolean resetPosition)867   void setMediaItem(MediaItem mediaItem, boolean resetPosition);
868 
869   /**
870    * Adds a media item to the end of the playlist.
871    *
872    * @param mediaItem The {@link MediaItem} to add.
873    */
addMediaItem(MediaItem mediaItem)874   void addMediaItem(MediaItem mediaItem);
875 
876   /**
877    * Adds a media item at the given index of the playlist.
878    *
879    * @param index The index at which to add the item.
880    * @param mediaItem The {@link MediaItem} to add.
881    */
addMediaItem(int index, MediaItem mediaItem)882   void addMediaItem(int index, MediaItem mediaItem);
883 
884   /**
885    * Adds a list of media items to the end of the playlist.
886    *
887    * @param mediaItems The {@link MediaItem MediaItems} to add.
888    */
addMediaItems(List<MediaItem> mediaItems)889   void addMediaItems(List<MediaItem> mediaItems);
890 
891   /**
892    * Adds a list of media items at the given index of the playlist.
893    *
894    * @param index The index at which to add the media items.
895    * @param mediaItems The {@link MediaItem MediaItems} to add.
896    */
addMediaItems(int index, List<MediaItem> mediaItems)897   void addMediaItems(int index, List<MediaItem> mediaItems);
898 
899   /**
900    * Moves the media item at the current index to the new index.
901    *
902    * @param currentIndex The current index of the media item to move.
903    * @param newIndex The new index of the media item. If the new index is larger than the size of
904    *     the playlist the item is moved to the end of the playlist.
905    */
moveMediaItem(int currentIndex, int newIndex)906   void moveMediaItem(int currentIndex, int newIndex);
907 
908   /**
909    * Moves the media item range to the new index.
910    *
911    * @param fromIndex The start of the range to move.
912    * @param toIndex The first item not to be included in the range (exclusive).
913    * @param newIndex The new index of the first media item of the range. If the new index is larger
914    *     than the size of the remaining playlist after removing the range, the range is moved to the
915    *     end of the playlist.
916    */
moveMediaItems(int fromIndex, int toIndex, int newIndex)917   void moveMediaItems(int fromIndex, int toIndex, int newIndex);
918 
919   /**
920    * Removes the media item at the given index of the playlist.
921    *
922    * @param index The index at which to remove the media item.
923    */
removeMediaItem(int index)924   void removeMediaItem(int index);
925 
926   /**
927    * Removes a range of media items from the playlist.
928    *
929    * @param fromIndex The index at which to start removing media items.
930    * @param toIndex The index of the first item to be kept (exclusive).
931    */
removeMediaItems(int fromIndex, int toIndex)932   void removeMediaItems(int fromIndex, int toIndex);
933 
934   /** Clears the playlist. */
clearMediaItems()935   void clearMediaItems();
936 
937   /** Prepares the player. */
prepare()938   void prepare();
939 
940   /**
941    * Returns the current {@link State playback state} of the player.
942    *
943    * @return The current {@link State playback state}.
944    */
945   @State
getPlaybackState()946   int getPlaybackState();
947 
948   /**
949    * Returns the reason why playback is suppressed even though {@link #getPlayWhenReady()} is {@code
950    * true}, or {@link #PLAYBACK_SUPPRESSION_REASON_NONE} if playback is not suppressed.
951    *
952    * @return The current {@link PlaybackSuppressionReason playback suppression reason}.
953    */
954   @PlaybackSuppressionReason
getPlaybackSuppressionReason()955   int getPlaybackSuppressionReason();
956 
957   /**
958    * Returns whether the player is playing, i.e. {@link #getContentPosition()} is advancing.
959    *
960    * <p>If {@code false}, then at least one of the following is true:
961    *
962    * <ul>
963    *   <li>The {@link #getPlaybackState() playback state} is not {@link #STATE_READY ready}.
964    *   <li>There is no {@link #getPlayWhenReady() intention to play}.
965    *   <li>Playback is {@link #getPlaybackSuppressionReason() suppressed for other reasons}.
966    * </ul>
967    *
968    * @return Whether the player is playing.
969    */
isPlaying()970   boolean isPlaying();
971 
972   /**
973    * Returns the error that caused playback to fail. This is the same error that will have been
974    * reported via {@link Player.EventListener#onPlayerError(ExoPlaybackException)} at the time of
975    * failure. It can be queried using this method until {@code stop(true)} is called or the player
976    * is re-prepared.
977    *
978    * <p>Note that this method will always return {@code null} if {@link #getPlaybackState()} is not
979    * {@link #STATE_IDLE}.
980    *
981    * @return The error, or {@code null}.
982    */
983   @Nullable
getPlayerError()984   ExoPlaybackException getPlayerError();
985 
986   /** @deprecated Use {@link #getPlayerError()} instead. */
987   @Deprecated
988   @Nullable
getPlaybackError()989   ExoPlaybackException getPlaybackError();
990 
991   /**
992    * Resumes playback as soon as {@link #getPlaybackState()} == {@link #STATE_READY}. Equivalent to
993    * {@code setPlayWhenReady(true)}.
994    */
play()995   void play();
996 
997   /** Pauses playback. Equivalent to {@code setPlayWhenReady(false)}. */
pause()998   void pause();
999 
1000   /**
1001    * Sets whether playback should proceed when {@link #getPlaybackState()} == {@link #STATE_READY}.
1002    *
1003    * <p>If the player is already in the ready state then this method pauses and resumes playback.
1004    *
1005    * @param playWhenReady Whether playback should proceed when ready.
1006    */
setPlayWhenReady(boolean playWhenReady)1007   void setPlayWhenReady(boolean playWhenReady);
1008 
1009   /**
1010    * Whether playback will proceed when {@link #getPlaybackState()} == {@link #STATE_READY}.
1011    *
1012    * @return Whether playback will proceed when ready.
1013    */
getPlayWhenReady()1014   boolean getPlayWhenReady();
1015 
1016   /**
1017    * Sets the {@link RepeatMode} to be used for playback.
1018    *
1019    * @param repeatMode The repeat mode.
1020    */
setRepeatMode(@epeatMode int repeatMode)1021   void setRepeatMode(@RepeatMode int repeatMode);
1022 
1023   /**
1024    * Returns the current {@link RepeatMode} used for playback.
1025    *
1026    * @return The current repeat mode.
1027    */
getRepeatMode()1028   @RepeatMode int getRepeatMode();
1029 
1030   /**
1031    * Sets whether shuffling of windows is enabled.
1032    *
1033    * @param shuffleModeEnabled Whether shuffling is enabled.
1034    */
setShuffleModeEnabled(boolean shuffleModeEnabled)1035   void setShuffleModeEnabled(boolean shuffleModeEnabled);
1036 
1037   /**
1038    * Returns whether shuffling of windows is enabled.
1039    */
getShuffleModeEnabled()1040   boolean getShuffleModeEnabled();
1041 
1042   /**
1043    * Whether the player is currently loading the source.
1044    *
1045    * @return Whether the player is currently loading the source.
1046    */
isLoading()1047   boolean isLoading();
1048 
1049   /**
1050    * Seeks to the default position associated with the current window. The position can depend on
1051    * the type of media being played. For live streams it will typically be the live edge of the
1052    * window. For other streams it will typically be the start of the window.
1053    */
seekToDefaultPosition()1054   void seekToDefaultPosition();
1055 
1056   /**
1057    * Seeks to the default position associated with the specified window. The position can depend on
1058    * the type of media being played. For live streams it will typically be the live edge of the
1059    * window. For other streams it will typically be the start of the window.
1060    *
1061    * @param windowIndex The index of the window whose associated default position should be seeked
1062    *     to.
1063    */
seekToDefaultPosition(int windowIndex)1064   void seekToDefaultPosition(int windowIndex);
1065 
1066   /**
1067    * Seeks to a position specified in milliseconds in the current window.
1068    *
1069    * @param positionMs The seek position in the current window, or {@link C#TIME_UNSET} to seek to
1070    *     the window's default position.
1071    */
seekTo(long positionMs)1072   void seekTo(long positionMs);
1073 
1074   /**
1075    * Seeks to a position specified in milliseconds in the specified window.
1076    *
1077    * @param windowIndex The index of the window.
1078    * @param positionMs The seek position in the specified window, or {@link C#TIME_UNSET} to seek to
1079    *     the window's default position.
1080    * @throws IllegalSeekPositionException If the player has a non-empty timeline and the provided
1081    *     {@code windowIndex} is not within the bounds of the current timeline.
1082    */
seekTo(int windowIndex, long positionMs)1083   void seekTo(int windowIndex, long positionMs);
1084 
1085   /**
1086    * Returns whether a previous window exists, which may depend on the current repeat mode and
1087    * whether shuffle mode is enabled.
1088    */
hasPrevious()1089   boolean hasPrevious();
1090 
1091   /**
1092    * Seeks to the default position of the previous window in the timeline, which may depend on the
1093    * current repeat mode and whether shuffle mode is enabled. Does nothing if {@link #hasPrevious()}
1094    * is {@code false}.
1095    */
previous()1096   void previous();
1097 
1098   /**
1099    * Returns whether a next window exists, which may depend on the current repeat mode and whether
1100    * shuffle mode is enabled.
1101    */
hasNext()1102   boolean hasNext();
1103 
1104   /**
1105    * Seeks to the default position of the next window in the timeline, which may depend on the
1106    * current repeat mode and whether shuffle mode is enabled. Does nothing if {@link #hasNext()} is
1107    * {@code false}.
1108    */
next()1109   void next();
1110 
1111   /**
1112    * @deprecated Use {@link #setPlaybackSpeed(float)} or {@link
1113    *     AudioComponent#setSkipSilenceEnabled(boolean)} instead.
1114    */
1115   @SuppressWarnings("deprecation")
1116   @Deprecated
setPlaybackParameters(@ullable PlaybackParameters playbackParameters)1117   void setPlaybackParameters(@Nullable PlaybackParameters playbackParameters);
1118 
1119   /**
1120    * @deprecated Use {@link #getPlaybackSpeed()} or {@link AudioComponent#getSkipSilenceEnabled()}
1121    *     instead.
1122    */
1123   @SuppressWarnings("deprecation")
1124   @Deprecated
getPlaybackParameters()1125   PlaybackParameters getPlaybackParameters();
1126 
1127   /**
1128    * Attempts to set the playback speed.
1129    *
1130    * <p>Playback speed changes may cause the player to buffer. {@link
1131    * EventListener#onPlaybackSpeedChanged(float)} will be called whenever the currently active
1132    * playback speed change.
1133    *
1134    * @param playbackSpeed The playback speed.
1135    */
setPlaybackSpeed(float playbackSpeed)1136   void setPlaybackSpeed(float playbackSpeed);
1137 
1138   /**
1139    * Returns the currently active playback speed.
1140    *
1141    * @see EventListener#onPlaybackSpeedChanged(float)
1142    */
getPlaybackSpeed()1143   float getPlaybackSpeed();
1144 
1145   /**
1146    * Stops playback without resetting the player. Use {@link #pause()} rather than this method if
1147    * the intention is to pause playback.
1148    *
1149    * <p>Calling this method will cause the playback state to transition to {@link #STATE_IDLE}. The
1150    * player instance can still be used, and {@link #release()} must still be called on the player if
1151    * it's no longer required.
1152    *
1153    * <p>Calling this method does not reset the playback position.
1154    */
stop()1155   void stop();
1156 
1157   /**
1158    * Stops playback and optionally resets the player. Use {@link #pause()} rather than this method
1159    * if the intention is to pause playback.
1160    *
1161    * <p>Calling this method will cause the playback state to transition to {@link #STATE_IDLE}. The
1162    * player instance can still be used, and {@link #release()} must still be called on the player if
1163    * it's no longer required.
1164    *
1165    * @param reset Whether the player should be reset.
1166    */
stop(boolean reset)1167   void stop(boolean reset);
1168 
1169   /**
1170    * Releases the player. This method must be called when the player is no longer required. The
1171    * player must not be used after calling this method.
1172    */
release()1173   void release();
1174 
1175   /**
1176    * Returns the number of renderers.
1177    */
getRendererCount()1178   int getRendererCount();
1179 
1180   /**
1181    * Returns the track type that the renderer at a given index handles.
1182    *
1183    * @see Renderer#getTrackType()
1184    * @param index The index of the renderer.
1185    * @return One of the {@code TRACK_TYPE_*} constants defined in {@link C}.
1186    */
getRendererType(int index)1187   int getRendererType(int index);
1188 
1189   /**
1190    * Returns the available track groups.
1191    */
getCurrentTrackGroups()1192   TrackGroupArray getCurrentTrackGroups();
1193 
1194   /**
1195    * Returns the current track selections for each renderer.
1196    */
getCurrentTrackSelections()1197   TrackSelectionArray getCurrentTrackSelections();
1198 
1199   /**
1200    * Returns the current manifest. The type depends on the type of media being played. May be null.
1201    */
getCurrentManifest()1202   @Nullable Object getCurrentManifest();
1203 
1204   /**
1205    * Returns the current {@link Timeline}. Never null, but may be empty.
1206    */
getCurrentTimeline()1207   Timeline getCurrentTimeline();
1208 
1209   /**
1210    * Returns the index of the period currently being played.
1211    */
getCurrentPeriodIndex()1212   int getCurrentPeriodIndex();
1213 
1214   /**
1215    * Returns the index of the window currently being played.
1216    */
getCurrentWindowIndex()1217   int getCurrentWindowIndex();
1218 
1219   /**
1220    * Returns the index of the next timeline window to be played, which may depend on the current
1221    * repeat mode and whether shuffle mode is enabled. Returns {@link C#INDEX_UNSET} if the window
1222    * currently being played is the last window.
1223    */
getNextWindowIndex()1224   int getNextWindowIndex();
1225 
1226   /**
1227    * Returns the index of the previous timeline window to be played, which may depend on the current
1228    * repeat mode and whether shuffle mode is enabled. Returns {@link C#INDEX_UNSET} if the window
1229    * currently being played is the first window.
1230    */
getPreviousWindowIndex()1231   int getPreviousWindowIndex();
1232 
1233   /**
1234    * Returns the tag of the currently playing window in the timeline. May be null if no tag is set
1235    * or the timeline is not yet available.
1236    */
getCurrentTag()1237   @Nullable Object getCurrentTag();
1238 
1239   /**
1240    * Returns the duration of the current content window or ad in milliseconds, or {@link
1241    * C#TIME_UNSET} if the duration is not known.
1242    */
getDuration()1243   long getDuration();
1244 
1245   /** Returns the playback position in the current content window or ad, in milliseconds. */
getCurrentPosition()1246   long getCurrentPosition();
1247 
1248   /**
1249    * Returns an estimate of the position in the current content window or ad up to which data is
1250    * buffered, in milliseconds.
1251    */
getBufferedPosition()1252   long getBufferedPosition();
1253 
1254   /**
1255    * Returns an estimate of the percentage in the current content window or ad up to which data is
1256    * buffered, or 0 if no estimate is available.
1257    */
getBufferedPercentage()1258   int getBufferedPercentage();
1259 
1260   /**
1261    * Returns an estimate of the total buffered duration from the current position, in milliseconds.
1262    * This includes pre-buffered data for subsequent ads and windows.
1263    */
getTotalBufferedDuration()1264   long getTotalBufferedDuration();
1265 
1266   /**
1267    * Returns whether the current window is dynamic, or {@code false} if the {@link Timeline} is
1268    * empty.
1269    *
1270    * @see Timeline.Window#isDynamic
1271    */
isCurrentWindowDynamic()1272   boolean isCurrentWindowDynamic();
1273 
1274   /**
1275    * Returns whether the current window is live, or {@code false} if the {@link Timeline} is empty.
1276    *
1277    * @see Timeline.Window#isLive
1278    */
isCurrentWindowLive()1279   boolean isCurrentWindowLive();
1280 
1281   /**
1282    * Returns the offset of the current playback position from the live edge in milliseconds, or
1283    * {@link C#TIME_UNSET} if the current window {@link #isCurrentWindowLive() isn't live} or the
1284    * offset is unknown.
1285    *
1286    * <p>The offset is calculated as {@code currentTime - playbackPosition}, so should usually be
1287    * positive.
1288    *
1289    * <p>Note that this offset may rely on an accurate local time, so this method may return an
1290    * incorrect value if the difference between system clock and server clock is unknown.
1291    */
getCurrentLiveOffset()1292   long getCurrentLiveOffset();
1293 
1294   /**
1295    * Returns whether the current window is seekable, or {@code false} if the {@link Timeline} is
1296    * empty.
1297    *
1298    * @see Timeline.Window#isSeekable
1299    */
isCurrentWindowSeekable()1300   boolean isCurrentWindowSeekable();
1301 
1302   /**
1303    * Returns whether the player is currently playing an ad.
1304    */
isPlayingAd()1305   boolean isPlayingAd();
1306 
1307   /**
1308    * If {@link #isPlayingAd()} returns true, returns the index of the ad group in the period
1309    * currently being played. Returns {@link C#INDEX_UNSET} otherwise.
1310    */
getCurrentAdGroupIndex()1311   int getCurrentAdGroupIndex();
1312 
1313   /**
1314    * If {@link #isPlayingAd()} returns true, returns the index of the ad in its ad group. Returns
1315    * {@link C#INDEX_UNSET} otherwise.
1316    */
getCurrentAdIndexInAdGroup()1317   int getCurrentAdIndexInAdGroup();
1318 
1319   /**
1320    * If {@link #isPlayingAd()} returns {@code true}, returns the duration of the current content
1321    * window in milliseconds, or {@link C#TIME_UNSET} if the duration is not known. If there is no ad
1322    * playing, the returned duration is the same as that returned by {@link #getDuration()}.
1323    */
getContentDuration()1324   long getContentDuration();
1325 
1326   /**
1327    * If {@link #isPlayingAd()} returns {@code true}, returns the content position that will be
1328    * played once all ads in the ad group have finished playing, in milliseconds. If there is no ad
1329    * playing, the returned position is the same as that returned by {@link #getCurrentPosition()}.
1330    */
getContentPosition()1331   long getContentPosition();
1332 
1333   /**
1334    * If {@link #isPlayingAd()} returns {@code true}, returns an estimate of the content position in
1335    * the current content window up to which data is buffered, in milliseconds. If there is no ad
1336    * playing, the returned position is the same as that returned by {@link #getBufferedPosition()}.
1337    */
getContentBufferedPosition()1338   long getContentBufferedPosition();
1339 }
1340