diff --git a/app/src/main/java/com/theoplayer/android/ui/demo/MainActivity.kt b/app/src/main/java/com/theoplayer/android/ui/demo/MainActivity.kt index ae86248..f8f579f 100644 --- a/app/src/main/java/com/theoplayer/android/ui/demo/MainActivity.kt +++ b/app/src/main/java/com/theoplayer/android/ui/demo/MainActivity.kt @@ -44,7 +44,7 @@ fun MainContent() { val player = rememberPlayer() LaunchedEffect(player, source) { - player.player?.source = source + player.source = source } var themeMenuOpen by remember { mutableStateOf(false) } diff --git a/app/src/main/java/com/theoplayer/android/ui/demo/nitflex/NitflexUI.kt b/app/src/main/java/com/theoplayer/android/ui/demo/nitflex/NitflexUI.kt index 8aed80b..39520cb 100644 --- a/app/src/main/java/com/theoplayer/android/ui/demo/nitflex/NitflexUI.kt +++ b/app/src/main/java/com/theoplayer/android/ui/demo/nitflex/NitflexUI.kt @@ -50,7 +50,7 @@ fun NitflexUI( ) { val player = rememberPlayer(config) LaunchedEffect(player, source) { - player.player?.source = source + player.source = source } NitflexUI(modifier = modifier, player = player, title = title) diff --git a/ui/src/main/java/com/theoplayer/android/ui/DefaultUI.kt b/ui/src/main/java/com/theoplayer/android/ui/DefaultUI.kt index 86c2974..e5ee866 100644 --- a/ui/src/main/java/com/theoplayer/android/ui/DefaultUI.kt +++ b/ui/src/main/java/com/theoplayer/android/ui/DefaultUI.kt @@ -43,7 +43,7 @@ fun DefaultUI( ) { val player = rememberPlayer(config) LaunchedEffect(player, source) { - player.player?.source = source + player.source = source } DefaultUI(modifier = modifier, player = player, title = title) diff --git a/ui/src/main/java/com/theoplayer/android/ui/PlayButton.kt b/ui/src/main/java/com/theoplayer/android/ui/PlayButton.kt index 90af5db..a0d6479 100644 --- a/ui/src/main/java/com/theoplayer/android/ui/PlayButton.kt +++ b/ui/src/main/java/com/theoplayer/android/ui/PlayButton.kt @@ -54,9 +54,9 @@ fun PlayButton( onClick = { player?.let { if (it.paused) { - it.player?.play() + it.play() } else { - it.player?.pause() + it.pause() } } }) { diff --git a/ui/src/main/java/com/theoplayer/android/ui/Player.kt b/ui/src/main/java/com/theoplayer/android/ui/Player.kt index c3fae9e..be32c17 100644 --- a/ui/src/main/java/com/theoplayer/android/ui/Player.kt +++ b/ui/src/main/java/com/theoplayer/android/ui/Player.kt @@ -43,6 +43,7 @@ import com.theoplayer.android.api.player.track.mediatrack.quality.VideoQuality import com.theoplayer.android.api.player.track.texttrack.TextTrack import com.theoplayer.android.api.player.track.texttrack.TextTrackKind import com.theoplayer.android.api.player.track.texttrack.TextTrackMode +import com.theoplayer.android.api.source.SourceDescription import com.theoplayer.android.api.event.track.mediatrack.audio.list.AddTrackEvent as AudioAddTrackEvent import com.theoplayer.android.api.event.track.mediatrack.audio.list.RemoveTrackEvent as AudioRemoveTrackEvent import com.theoplayer.android.api.event.track.mediatrack.audio.list.TrackListChangeEvent as AudioTrackListChangeEvent @@ -81,6 +82,11 @@ interface Player { */ val theoplayerView: THEOplayerView? + /** + * Returns or sets the player's source. + */ + var source: SourceDescription? + /** * Returns the raw [Cast] API of the backing THEOplayer instance. */ @@ -231,6 +237,16 @@ interface Player { */ val castReceiverName: String? + /** + * Starts or resumes playback. + */ + fun play() + + /** + * Pauses playback. + */ + fun pause() + /** * Contains properties to access the current [Player]. */ @@ -327,6 +343,7 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player EventListener { updateCurrentTimeAndPlaybackState() } private val resizeListener = EventListener { updateVideoWidthAndHeight() } private val sourceChangeListener = EventListener { + _source = player?.source error = null firstPlay = false updateCurrentTimeAndPlaybackState() @@ -335,6 +352,7 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player updateActiveVideoTrack() } private val errorListener = EventListener { event -> + _source = player?.source error = event.errorObject updateCurrentTimeAndPlaybackState() updateDuration() @@ -342,6 +360,24 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player updateActiveVideoTrack() } + override fun play() { + paused = false + player?.play() + } + + override fun pause() { + paused = true + player?.pause() + } + + private var _source by mutableStateOf(player?.source) + override var source: SourceDescription? + get() = _source + set(value) { + _source = value + player?.source = value + } + private var _volume by mutableStateOf(1.0) private var _muted by mutableStateOf(false) override var volume: Double diff --git a/ui/src/main/java/com/theoplayer/android/ui/UIController.kt b/ui/src/main/java/com/theoplayer/android/ui/UIController.kt index 13e5346..72ea910 100644 --- a/ui/src/main/java/com/theoplayer/android/ui/UIController.kt +++ b/ui/src/main/java/com/theoplayer/android/ui/UIController.kt @@ -65,7 +65,7 @@ fun UIController( ) { val player = rememberPlayer(config) LaunchedEffect(player, source) { - player.player?.source = source + player.source = source } UIController(