FakePlayer
@UnstableApi
class FakePlayer : SimpleBasePlayer
| kotlin.Any | |||
| ↳ | androidx.media3.common.BasePlayer | ||
| ↳ | androidx.media3.common.SimpleBasePlayer | ||
| ↳ | androidx.media3.test.utils.FakePlayer |
A fake Player that uses SimpleBasePlayer's minimal number of default methods implementations to build upon to simulate realistic playback scenarios for testing.
Summary
Public constructors |
|---|
FakePlayer( |
Public functions |
|
|---|---|
Unit |
addCommands(vararg commands: @Player.Command Int)Add commands to those already available to the player. |
Unit |
removeCommands(vararg commands: @Player.Command Int)Remove commands from those already available to the player. |
Unit |
renderFirstFrame(newlyRenderedFirstFrame: Boolean)Sets whether a frame has been rendered for the first time since setting the surface, a rendering reset, or since the stream being rendered was changed. |
Unit |
setBufferedPositionMs(bufferedPositionMs: Long)Sets the buffered content playback position in milliseconds. |
Unit |
setDuration(uid: String, durationMs: Long)Sets the duration of the media item in the playlist, in milliseconds. |
Unit |
setPlaybackState(playbackState: @Player.State Int)Sets the {@linkplain Player.State state} of the player. |
Unit |
setPosition(positionMs: Long)Sets the current content playback position in milliseconds. |
Unit |
setPositionSupplierDrivenBy(testScheduler: TestCoroutineScheduler)Sets the PositionSupplier for the current content playback position using extrapolation. |
Unit |
setSeekBackIncrementMs(seekBackIncrementMs: Long)Sets the |
Unit |
setSeekForwardIncrementMs(seekForwardIncrementMs: Long)Sets the |
Unit |
setVideoSize(videoSize: VideoSize)Sets the current video size. |
Protected functions |
|
|---|---|
open SimpleBasePlayer.State |
getState()Returns the current |
open ListenableFuture<*> |
handleClearVideoOutput(videoOutput: Any?)Handles calls to clear the video output. |
open ListenableFuture<*> |
Handles calls to |
open ListenableFuture<*> |
Handles calls to |
open ListenableFuture<*> |
handleSeek(Handles calls to seekTo and other seek operations (for example, |
open ListenableFuture<*> |
handleSetMediaItems(Handles calls to setMediaItem and setMediaItems. |
open ListenableFuture<*> |
handleSetPlayWhenReady(playWhenReady: Boolean)Handles calls to |
open ListenableFuture<*> |
handleSetPlaybackParameters(playbackParameters: PlaybackParameters)Handles calls to |
open ListenableFuture<*> |
handleSetRepeatMode(repeatMode: Int)Handles calls to |
open ListenableFuture<*> |
handleSetShuffleModeEnabled(shuffleModeEnabled: Boolean)Handles calls to |
open ListenableFuture<*> |
handleSetTrackSelectionParameters(Handles calls to |
open ListenableFuture<*> |
handleSetVideoOutput(videoOutput: Any)Handles calls to set the video output. |
open ListenableFuture<*> |
handleSetVolume(Handles calls to |
open ListenableFuture<*> |
Handles calls to |
Inherited functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited properties |
|---|
Public constructors
FakePlayer
FakePlayer(
playbackState: @Player.State Int = STATE_IDLE,
playWhenReady: Boolean = false,
playlist: List<SimpleBasePlayer.MediaItemData> = ImmutableList.of(),
playbackSpeed: Float = 1.0f,
bufferingDelayMs: Long = 100
)
| Parameters | |
|---|---|
playbackState: @Player.State Int = STATE_IDLE |
The initial playback state of the player. |
playWhenReady: Boolean = false |
Whether playback should start automatically when ready. |
playlist: List<SimpleBasePlayer.MediaItemData> = ImmutableList.of() |
The initial list of media items to play. |
playbackSpeed: Float = 1.0f |
The initial playback speed. |
bufferingDelayMs: Long = 100 |
The time spent in Player#STATE_BUFFERING when preparing or seeking, in milliseconds. A value of zero will result in the player transitioning directly to Player#STATE_READY without entering Player#STATE_BUFFERING. Must not be negative. |
Public functions
addCommands
fun addCommands(vararg commands: @Player.Command Int): Unit
Add commands to those already available to the player.
removeCommands
fun removeCommands(vararg commands: @Player.Command Int): Unit
Remove commands from those already available to the player.
renderFirstFrame
fun renderFirstFrame(newlyRenderedFirstFrame: Boolean): Unit
Sets whether a frame has been rendered for the first time since setting the surface, a rendering reset, or since the stream being rendered was changed.
setBufferedPositionMs
fun setBufferedPositionMs(bufferedPositionMs: Long): Unit
Sets the buffered content playback position in milliseconds.
| Parameters | |
|---|---|
bufferedPositionMs: Long |
The buffered content playback position in milliseconds. |
setDuration
fun setDuration(uid: String, durationMs: Long): Unit
Sets the duration of the media item in the playlist, in milliseconds.
setPlaybackState
fun setPlaybackState(playbackState: @Player.State Int): Unit
Sets the {@linkplain Player.State state} of the player.
If the playlist is empty, the state must be either Player.STATE_IDLE or Player.STATE_ENDED.
| Parameters | |
|---|---|
playbackState: @Player.State Int |
The |
setPosition
fun setPosition(positionMs: Long): Unit
Sets the current content playback position in milliseconds.
| Parameters | |
|---|---|
positionMs: Long |
The current content playback position in milliseconds, or |
setPositionSupplierDrivenBy
fun setPositionSupplierDrivenBy(testScheduler: TestCoroutineScheduler): Unit
Sets the PositionSupplier for the current content playback position using extrapolation. Start and elapsed time are measured using the TestCoroutineScheduler, and playback speed is taken into account.
Note, that this approach only works
-
for a single media item (does not consider current item's duration and playlist length)
-
assuming the Player is playing (does not react to pauses and discontinuities)
-
assuming the playback speed does not change after the supplier is set
setSeekBackIncrementMs
fun setSeekBackIncrementMs(seekBackIncrementMs: Long): Unit
Sets the Player.seekBack increment in milliseconds.
| Parameters | |
|---|---|
seekBackIncrementMs: Long |
The |
setSeekForwardIncrementMs
fun setSeekForwardIncrementMs(seekForwardIncrementMs: Long): Unit
Sets the Player.seekForward increment in milliseconds.
| Parameters | |
|---|---|
seekForwardIncrementMs: Long |
The |
setVideoSize
fun setVideoSize(videoSize: VideoSize): Unit
Sets the current video size.
| Parameters | |
|---|---|
videoSize: VideoSize |
The current video size. |
Protected functions
getState
protected open fun getState(): SimpleBasePlayer.State
Returns the current State of the player.
The State should include all available commands indicating which player methods are allowed to be called.
Note that this method won't be called while asynchronous handling of player methods is in progress. This means that the implementation doesn't need to handle state changes caused by these asynchronous operations until they are done and can return the currently known state directly. The placeholder state used while these asynchronous operations are in progress can be customized by overriding getPlaceholderState if required.
handleClearVideoOutput
protected open fun handleClearVideoOutput(videoOutput: Any?): ListenableFuture<*>
Handles calls to clear the video output.
Will only be called if COMMAND_SET_VIDEO_SURFACE is available.
| Parameters | |
|---|---|
videoOutput: Any? |
The video output to clear. If null any current output should be cleared. If non-null, the output should only be cleared if it matches the provided argument. This is either a |
| Returns | |
|---|---|
ListenableFuture<*> |
A |
handlePrepare
protected open fun handlePrepare(): ListenableFuture<*>
Handles calls to prepare.
Will only be called if COMMAND_PREPARE is available.
| Returns | |
|---|---|
ListenableFuture<*> |
A |
handleRelease
protected open fun handleRelease(): ListenableFuture<*>
Handles calls to release.
Will only be called if COMMAND_RELEASE is available.
| Returns | |
|---|---|
ListenableFuture<*> |
A |
handleSeek
protected open fun handleSeek(
mediaItemIndex: Int,
positionMs: Long,
seekCommand: @Player.Command Int
): ListenableFuture<*>
Handles calls to seekTo and other seek operations (for example, seekToNext).
Will only be called if the appropriate Player.Command, for example COMMAND_SEEK_TO_MEDIA_ITEM or COMMAND_SEEK_TO_NEXT, is available.
| Parameters | |
|---|---|
mediaItemIndex: Int |
The media item index to seek to. If the original seek operation did not directly specify an index, this is the most likely implied index based on the available player state. If the implied action is to do nothing, this will be |
positionMs: Long |
The position in milliseconds to start playback from, or |
seekCommand: @Player.Command Int |
The |
| Returns | |
|---|---|
ListenableFuture<*> |
A |
handleSetMediaItems
protected open fun handleSetMediaItems(
mediaItems: MutableList<MediaItem>,
startIndex: Int,
startPositionMs: Long
): ListenableFuture<*>
Handles calls to setMediaItem and setMediaItems.
Will only be called if COMMAND_SET_MEDIA_ITEM or COMMAND_CHANGE_MEDIA_ITEMS is available. If only COMMAND_SET_MEDIA_ITEM is available, the list of media items will always contain exactly one item.
| Parameters | |
|---|---|
mediaItems: MutableList<MediaItem> |
The media items to add. |
startIndex: Int |
The index at which to start playback from, or |
startPositionMs: Long |
The position in milliseconds to start playback from, or |
| Returns | |
|---|---|
ListenableFuture<*> |
A |
handleSetPlayWhenReady
protected open fun handleSetPlayWhenReady(playWhenReady: Boolean): ListenableFuture<*>
Handles calls to setPlayWhenReady, play and pause.
Will only be called if COMMAND_PLAY_PAUSE is available.
| Parameters | |
|---|---|
playWhenReady: Boolean |
The requested |
| Returns | |
|---|---|
ListenableFuture<*> |
A |
handleSetPlaybackParameters
protected open fun handleSetPlaybackParameters(playbackParameters: PlaybackParameters): ListenableFuture<*>
Handles calls to setPlaybackParameters or setPlaybackSpeed.
Will only be called if COMMAND_SET_SPEED_AND_PITCH is available.
| Parameters | |
|---|---|
playbackParameters: PlaybackParameters |
The requested |
| Returns | |
|---|---|
ListenableFuture<*> |
A |
handleSetRepeatMode
protected open fun handleSetRepeatMode(repeatMode: Int): ListenableFuture<*>
Handles calls to setRepeatMode.
Will only be called if COMMAND_SET_REPEAT_MODE is available.
| Parameters | |
|---|---|
repeatMode: Int |
The requested |
| Returns | |
|---|---|
ListenableFuture<*> |
A |
handleSetShuffleModeEnabled
protected open fun handleSetShuffleModeEnabled(shuffleModeEnabled: Boolean): ListenableFuture<*>
Handles calls to setShuffleModeEnabled.
Will only be called if COMMAND_SET_SHUFFLE_MODE is available.
| Parameters | |
|---|---|
shuffleModeEnabled: Boolean |
Whether shuffle mode was requested to be enabled. |
| Returns | |
|---|---|
ListenableFuture<*> |
A |
handleSetTrackSelectionParameters
protected open fun handleSetTrackSelectionParameters(
trackSelectionParameters: TrackSelectionParameters
): ListenableFuture<*>
Handles calls to setTrackSelectionParameters.
Will only be called if COMMAND_SET_TRACK_SELECTION_PARAMETERS is available.
| Parameters | |
|---|---|
trackSelectionParameters: TrackSelectionParameters |
The requested |
| Returns | |
|---|---|
ListenableFuture<*> |
A |
handleSetVideoOutput
protected open fun handleSetVideoOutput(videoOutput: Any): ListenableFuture<*>
Handles calls to set the video output.
Will only be called if COMMAND_SET_VIDEO_SURFACE is available.
| Parameters | |
|---|---|
videoOutput: Any |
The requested video output. This is either a |
| Returns | |
|---|---|
ListenableFuture<*> |
A |
handleSetVolume
protected open fun handleSetVolume(
volume: Float,
volumeOperationType: @C.VolumeOperationType Int
): ListenableFuture<*>
Handles calls to setVolume.
Will only be called if COMMAND_SET_VOLUME is available.
| Parameters | |
|---|---|
volume: Float |
The requested audio volume, with 0 being silence and 1 being unity gain (signal unchanged). |
volumeOperationType: @C.VolumeOperationType Int |
The |
| Returns | |
|---|---|
ListenableFuture<*> |
A |
handleStop
protected open fun handleStop(): ListenableFuture<*>
Handles calls to stop.
Will only be called if COMMAND_STOP is available.
| Returns | |
|---|---|
ListenableFuture<*> |
A |