DefaultMediaPlayer

class DefaultMediaPlayer(createPlaybackStateRepo: (CoroutineContext) -> BasePlaybackStateRepo, coroutineContext: CoroutineContext) : MediaPlayer, CoroutineScope

A default implementation of MediaPlayer

Parameters

createPlaybackStateRepo

method for creating a BasePlaybackStateRepo to manage the PlaybackState of this player

coroutineContext

the CoroutineContext on which to run the media player

Constructors

Link copied to clipboard
constructor(mediaSurfaceProvider: MediaSurfaceProvider?, mediaManagerBuilder: BaseMediaManager.Builder, coroutineContext: CoroutineContext)

Constructor that provides a BaseMediaManager to manage media playback

constructor(createPlaybackStateRepo: (CoroutineContext) -> BasePlaybackStateRepo, coroutineContext: CoroutineContext)

Properties

Link copied to clipboard
open override val controls: Flow<MediaPlayer.Controls>

A Flow of the Controls available for playback

Link copied to clipboard
Link copied to clipboard
open override val currentVolume: Flow<Float>

The volume of the audio playback. A value of 0.0 indicates silence; a value of 1.0 (the default) indicates full audio volume for the player instance.

Link copied to clipboard

A Flow that provides the Duration of the current PlayableMedia of a MediaPlayer. If no PlayableMedia is loaded this will result in Duration.ZERO.

Link copied to clipboard
open override val playableMedia: Flow<PlayableMedia?>

A Flow of the PlayableMedia for which the player is controlling playback

Functions

Link copied to clipboard
open suspend override fun awaitCompletion()

Suspends until playback has completed

Link copied to clipboard
open override fun close()

Releases all resources associated with the media player. This method should be called when done with the media player. After calling this playback is disabled. Any subsequent calls will result in a PlaybackError.PlaybackHasEnded

Link copied to clipboard
open suspend override fun forceStart(playbackParameters: PlaybackState.PlaybackParameters, restartIfStarted: Boolean)

Suspends until playback has started.

Link copied to clipboard
open suspend override fun initializeFor(source: MediaSource)

Loads a MediaSource into a PlayableMedia to control playback for

Link copied to clipboard
suspend fun MediaPlayer.play(playbackParameters: PlaybackState.PlaybackParameters = PlaybackState.PlaybackParameters(), restartIfStarted: Boolean = false)

Forces the MediaPlayer to start playback and suspends until playback has completed

Link copied to clipboard
fun MediaPlayer.playTime(pollingInterval: Duration): Flow<Duration>

A Flow that polls the playtime of the current PlayableMedia of a MediaPlayer as a Duration. If no PlayableMedia is loaded this will result in Duration.ZERO.

Link copied to clipboard
open suspend override fun renderVideoOnSurface(surface: MediaSurface?)

Renders the video component of any initialized PlayableMedia on a MediaSurface

Link copied to clipboard
open suspend override fun reset()

Stops current playback and resets the player.

Link copied to clipboard
open suspend override fun updateVolume(volume: Float)

Updates the currentVolume