Class CastPlayer

  • All Implemented Interfaces:
    Player

    @Deprecated
    public final class CastPlayer
    extends BasePlayer
    Deprecated.
    com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.
    Player implementation that communicates with a Cast receiver app.

    The behavior of this class depends on the underlying Cast session, which is obtained from the injected CastContext. To keep track of the session, isCastSessionAvailable() can be queried and SessionAvailabilityListener can be implemented and attached to the player.

    If no session is available, the player state will remain unchanged and calls to methods that alter it will be ignored. Querying the player state is possible even when no session is available, in which case, the last observed receiver app state is reported.

    Methods should be called on the application's main thread.

    • Method Detail

      • getItem

        @Nullable
        public com.google.android.gms.cast.MediaQueueItem getItem​(int periodId)
        Deprecated.
        Returns the item that corresponds to the period with the given id, or null if no media queue or period with id periodId exist.
        Parameters:
        periodId - The id of the period (getCurrentTimeline()) that corresponds to the item to get.
        Returns:
        The item that corresponds to the period with the given id, or null if no media queue or period with id periodId exist.
      • isCastSessionAvailable

        public boolean isCastSessionAvailable()
        Deprecated.
        Returns whether a cast session is available.
      • setSessionAvailabilityListener

        public void setSessionAvailabilityListener​(@Nullable
                                                   SessionAvailabilityListener listener)
        Deprecated.
        Sets a listener for updates on the cast session availability.
        Parameters:
        listener - The SessionAvailabilityListener, or null to clear the listener.
      • getApplicationLooper

        public Looper getApplicationLooper()
        Deprecated.
        Description copied from interface: Player
        Returns the Looper associated with the application thread that's used to access the player and on which player events are received.

        This method can be called from any thread.

      • addListener

        public void addListener​(Player.Listener listener)
        Deprecated.
        Description copied from interface: Player
        Registers a listener to receive all events from the player.

        The listener's methods will be called on the thread associated with Player.getApplicationLooper().

        This method can be called from any thread.

        Parameters:
        listener - The listener to register.
      • removeListener

        public void removeListener​(Player.Listener listener)
        Deprecated.
        Description copied from interface: Player
        Unregister a listener registered through Player.addListener(Listener). The listener will no longer receive events.
        Parameters:
        listener - The listener to unregister.
      • setMediaItems

        public void setMediaItems​(List<MediaItem> mediaItems,
                                  int startIndex,
                                  long startPositionMs)
        Deprecated.
        Description copied from interface: Player
        Clears the playlist and adds the specified media items.

        This method must only be called if Player.COMMAND_CHANGE_MEDIA_ITEMS is available.

        Parameters:
        mediaItems - The new media items.
        startIndex - The MediaItem index to start playback from. If C.INDEX_UNSET is passed, the current position is not reset.
        startPositionMs - The position in milliseconds to start playback from. If C.TIME_UNSET is passed, the default position of the given MediaItem is used. In any case, if startIndex is set to C.INDEX_UNSET, this parameter is ignored and the position is not reset at all.
      • addMediaItems

        public void addMediaItems​(int index,
                                  List<MediaItem> mediaItems)
        Deprecated.
        Description copied from interface: Player
        Adds a list of media items at the given index of the playlist.

        This method must only be called if Player.COMMAND_CHANGE_MEDIA_ITEMS is available.

        Parameters:
        index - The index at which to add the media items. If the index is larger than the size of the playlist, the media items are added to the end of the playlist.
        mediaItems - The media items to add.
      • moveMediaItems

        public void moveMediaItems​(int fromIndex,
                                   int toIndex,
                                   int newIndex)
        Deprecated.
        Description copied from interface: Player
        Moves the media item range to the new index.

        This method must only be called if Player.COMMAND_CHANGE_MEDIA_ITEMS is available.

        Parameters:
        fromIndex - The start of the range to move. If the index is larger than the size of the playlist, the request is ignored.
        toIndex - The first item not to be included in the range (exclusive). If the index is larger than the size of the playlist, items up to the end of the playlist are moved.
        newIndex - The new index of the first media item of the range. If the new index is larger than the size of the remaining playlist after removing the range, the range is moved to the end of the playlist.
      • replaceMediaItems

        public void replaceMediaItems​(int fromIndex,
                                      int toIndex,
                                      List<MediaItem> mediaItems)
        Deprecated.
        Description copied from interface: Player
        Replaces the media items at the given range of the playlist.

        This method must only be called if Player.COMMAND_CHANGE_MEDIA_ITEMS is available.

        Note that it is possible to replace a range with an arbitrary number of new items, so that the number of removed items defined by fromIndex and toIndex does not have to match the number of added items defined by mediaItems. As result, it may also change the index of subsequent items not touched by this operation.

        Parameters:
        fromIndex - The start of the range. If the index is larger than the size of the playlist, the request is ignored.
        toIndex - The first item not to be included in the range (exclusive). If the index is larger than the size of the playlist, items up to the end of the playlist are replaced.
        mediaItems - The media items to replace the range with.
      • removeMediaItems

        public void removeMediaItems​(int fromIndex,
                                     int toIndex)
        Deprecated.
        Description copied from interface: Player
        Removes a range of media items from the playlist.

        This method must only be called if Player.COMMAND_CHANGE_MEDIA_ITEMS is available.

        Parameters:
        fromIndex - The index at which to start removing media items. If the index is larger than the size of the playlist, the request is ignored.
        toIndex - The index of the first item to be kept (exclusive). If the index is larger than the size of the playlist, media items up to the end of the playlist are removed.
      • prepare

        public void prepare()
        Deprecated.
        Description copied from interface: Player
        Prepares the player.

        This method must only be called if Player.COMMAND_PREPARE is available.

        This will move the player out of idle state and the player will start loading media and acquire resources needed for playback.

      • setPlayWhenReady

        public void setPlayWhenReady​(boolean playWhenReady)
        Deprecated.
        Description copied from interface: Player
        Sets whether playback should proceed when Player.getPlaybackState() == Player.STATE_READY.

        If the player is already in the ready state then this method pauses and resumes playback.

        This method must only be called if Player.COMMAND_PLAY_PAUSE is available.

        Parameters:
        playWhenReady - Whether playback should proceed when ready.
      • seekTo

        public void seekTo​(int mediaItemIndex,
                           long positionMs,
                           @Command
                           @com.google.android.exoplayer2.Player.Command int seekCommand,
                           boolean isRepeatingCurrentItem)
        Deprecated.
        Description copied from class: BasePlayer
        Seeks to a position in the specified MediaItem.
        Specified by:
        seekTo in class BasePlayer
        Parameters:
        mediaItemIndex - The index of the MediaItem.
        positionMs - The seek position in the specified MediaItem in milliseconds, or C.TIME_UNSET to seek to the media item's default position.
        seekCommand - The Player.Command used to trigger the seek.
        isRepeatingCurrentItem - Whether this seeks repeats the current item.
      • stop

        public void stop()
        Deprecated.
        Description copied from interface: Player
        Stops playback without resetting the playlist. Use Player.pause() rather than this method if the intention is to pause playback.

        Calling this method will cause the playback state to transition to Player.STATE_IDLE and the player will release the loaded media and resources required for playback. The player instance can still be used by calling Player.prepare() again, and Player.release() must still be called on the player if it's no longer required.

        Calling this method does not clear the playlist, reset the playback position or the playback error.

        This method must only be called if Player.COMMAND_STOP is available.

      • release

        public void release()
        Deprecated.
        Description copied from interface: Player
        Releases the player. This method must be called when the player is no longer required. The player must not be used after calling this method.

        This method must only be called if Player.COMMAND_RELEASE is available.

      • setShuffleModeEnabled

        public void setShuffleModeEnabled​(boolean shuffleModeEnabled)
        Deprecated.
        Description copied from interface: Player
        Sets whether shuffling of media items is enabled.

        This method must only be called if Player.COMMAND_SET_SHUFFLE_MODE is available.

        Parameters:
        shuffleModeEnabled - Whether shuffling is enabled.
      • getTrackSelectionParameters

        public TrackSelectionParameters getTrackSelectionParameters()
        Deprecated.
        Description copied from interface: Player
        Returns the parameters constraining the track selection.
        See Also:
        }
      • setTrackSelectionParameters

        public void setTrackSelectionParameters​(TrackSelectionParameters parameters)
        Deprecated.
        Description copied from interface: Player
        Sets the parameters constraining the track selection.

        Unsupported parameters will be silently ignored.

        Use Player.getTrackSelectionParameters() to retrieve the current parameters. For example, the following snippet restricts video to SD whilst keep other track selection parameters unchanged:

        
         player.setTrackSelectionParameters(
           player.getTrackSelectionParameters()
                 .buildUpon()
                 .setMaxVideoSizeSd()
                 .build())
         

        This method must only be called if Player.COMMAND_SET_TRACK_SELECTION_PARAMETERS is available.

      • getMediaMetadataInternal

        public MediaMetadata getMediaMetadataInternal()
        Deprecated.
      • setPlaylistMetadata

        public void setPlaylistMetadata​(MediaMetadata mediaMetadata)
        Deprecated.
        This method is not supported and does nothing.
      • getCurrentPeriodIndex

        public int getCurrentPeriodIndex()
        Deprecated.
        Description copied from interface: Player
        Returns the index of the period currently being played.

        This method must only be called if Player.COMMAND_GET_TIMELINE is available.

      • getCurrentPosition

        public long getCurrentPosition()
        Deprecated.
        Description copied from interface: Player
        Returns the playback position in the current content or ad, in milliseconds, or the prospective position in milliseconds if the current timeline is empty.

        This method must only be called if Player.COMMAND_GET_CURRENT_MEDIA_ITEM is available.

      • getBufferedPosition

        public long getBufferedPosition()
        Deprecated.
        Description copied from interface: Player
        Returns an estimate of the position in the current content or ad up to which data is buffered, in milliseconds.

        This method must only be called if Player.COMMAND_GET_CURRENT_MEDIA_ITEM is available.

      • getTotalBufferedDuration

        public long getTotalBufferedDuration()
        Deprecated.
        Description copied from interface: Player
        Returns an estimate of the total buffered duration from the current position, in milliseconds. This includes pre-buffered data for subsequent ads and media items.

        This method must only be called if Player.COMMAND_GET_CURRENT_MEDIA_ITEM is available.

      • isLoading

        public boolean isLoading()
        Deprecated.
        Description copied from interface: Player
        Whether the player is currently loading the source.
        Returns:
        Whether the player is currently loading the source.
        See Also:
        Player.Listener.onIsLoadingChanged(boolean)
      • setVolume

        public void setVolume​(float volume)
        Deprecated.
        This method is not supported and does nothing.
        Parameters:
        volume - Linear output gain to apply to all audio channels.
      • getVolume

        public float getVolume()
        Deprecated.
        This method is not supported and returns 1.
        Returns:
        The linear gain applied to all audio channels.
      • clearVideoSurface

        public void clearVideoSurface()
        Deprecated.
        This method is not supported and does nothing.
      • clearVideoSurface

        public void clearVideoSurface​(@Nullable
                                      Surface surface)
        Deprecated.
        This method is not supported and does nothing.
        Parameters:
        surface - The surface to clear.
      • setVideoSurface

        public void setVideoSurface​(@Nullable
                                    Surface surface)
        Deprecated.
        This method is not supported and does nothing.
        Parameters:
        surface - The Surface.
      • setVideoSurfaceHolder

        public void setVideoSurfaceHolder​(@Nullable
                                          SurfaceHolder surfaceHolder)
        Deprecated.
        This method is not supported and does nothing.
        Parameters:
        surfaceHolder - The surface holder.
      • clearVideoSurfaceHolder

        public void clearVideoSurfaceHolder​(@Nullable
                                            SurfaceHolder surfaceHolder)
        Deprecated.
        This method is not supported and does nothing.
        Parameters:
        surfaceHolder - The surface holder to clear.
      • setVideoSurfaceView

        public void setVideoSurfaceView​(@Nullable
                                        SurfaceView surfaceView)
        Deprecated.
        This method is not supported and does nothing.
        Parameters:
        surfaceView - The surface view.
      • clearVideoSurfaceView

        public void clearVideoSurfaceView​(@Nullable
                                          SurfaceView surfaceView)
        Deprecated.
        This method is not supported and does nothing.
        Parameters:
        surfaceView - The texture view to clear.
      • setVideoTextureView

        public void setVideoTextureView​(@Nullable
                                        TextureView textureView)
        Deprecated.
        This method is not supported and does nothing.
        Parameters:
        textureView - The texture view.
      • clearVideoTextureView

        public void clearVideoTextureView​(@Nullable
                                          TextureView textureView)
        Deprecated.
        This method is not supported and does nothing.
        Parameters:
        textureView - The texture view to clear.
      • getCurrentCues

        public CueGroup getCurrentCues()
        Deprecated.
        This method is not supported and returns an empty CueGroup.
      • getDeviceVolume

        public int getDeviceVolume()
        Deprecated.
        This method is not supported and always returns 0.
      • isDeviceMuted

        public boolean isDeviceMuted()
        Deprecated.
        This method is not supported and always returns false.
      • setDeviceVolume

        public void setDeviceVolume​(int volume,
                                    @com.google.android.exoplayer2.C.VolumeFlags int flags)
        Deprecated.
        This method is not supported and does nothing.
        Parameters:
        volume - The volume to set.
        flags - Either 0 or a bitwise combination of one or more C.VolumeFlags.
      • increaseDeviceVolume

        public void increaseDeviceVolume​(@com.google.android.exoplayer2.C.VolumeFlags int flags)
        Deprecated.
        This method is not supported and does nothing.
        Parameters:
        flags - Either 0 or a bitwise combination of one or more C.VolumeFlags.
      • decreaseDeviceVolume

        public void decreaseDeviceVolume​(@com.google.android.exoplayer2.C.VolumeFlags int flags)
        Deprecated.
        This method is not supported and does nothing.
        Parameters:
        flags - Either 0 or a bitwise combination of one or more C.VolumeFlags.
      • setDeviceMuted

        public void setDeviceMuted​(boolean muted,
                                   @com.google.android.exoplayer2.C.VolumeFlags int flags)
        Deprecated.
        This method is not supported and does nothing.
        Parameters:
        muted - Whether to set the device to be muted or not
        flags - Either 0 or a bitwise combination of one or more C.VolumeFlags.