mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-16 02:44:51 +00:00
fix(cast): handle end events
This commit is contained in:
@@ -15,6 +15,8 @@ import androidx.media3.common.Player.STATE_READY
|
||||
import androidx.media3.common.Timeline
|
||||
import androidx.media3.common.Tracks
|
||||
import androidx.media3.common.VideoSize
|
||||
import com.google.android.gms.cast.MediaStatus
|
||||
import com.google.android.gms.cast.framework.media.RemoteMediaClient
|
||||
import com.margelo.nitro.omni.BoolProperty
|
||||
import com.margelo.nitro.omni.CastStatus
|
||||
import com.margelo.nitro.omni.HybridOmniEventMapSpec
|
||||
@@ -103,6 +105,8 @@ class EventMap(private val tracks: TrackProvider) : HybridOmniEventMapSpec(), Pl
|
||||
onTracksChanged(value.currentTracks)
|
||||
}
|
||||
|
||||
var remote: RemoteMediaClient? = null
|
||||
|
||||
fun emitCastStatus(status: CastStatus) {
|
||||
castStatusListeners.forEach { it(status) }
|
||||
}
|
||||
@@ -200,7 +204,13 @@ class EventMap(private val tracks: TrackProvider) : HybridOmniEventMapSpec(), Pl
|
||||
|
||||
override fun onPlaybackStateChanged(playbackState: Int) {
|
||||
val state = when (player.playbackState) {
|
||||
STATE_IDLE -> PlayerStatus.IDLE
|
||||
STATE_IDLE -> {
|
||||
// cast doesn't have STATE_ENDED, so handle this manually
|
||||
if (remote?.mediaStatus?.idleReason == MediaStatus.IDLE_REASON_FINISHED)
|
||||
onEndListeners.forEach { it() }
|
||||
PlayerStatus.IDLE
|
||||
}
|
||||
|
||||
STATE_BUFFERING -> PlayerStatus.LOADING
|
||||
STATE_READY -> PlayerStatus.READYTOPLAY
|
||||
STATE_ENDED -> {
|
||||
|
||||
@@ -111,7 +111,9 @@ class OmniPlayer(
|
||||
// their own), so they ask us to do it when something else - google home, the
|
||||
// assistant, ... - requests a prev/next. same path as our own buttons.
|
||||
private fun listenToReceiver() {
|
||||
val session = castContext?.sessionManager?.currentCastSession ?: return
|
||||
val session = castContext?.sessionManager?.currentCastSession
|
||||
eventMap.remote = session?.remoteMediaClient
|
||||
if (session == null) return
|
||||
try {
|
||||
session.setMessageReceivedCallbacks(OMNI_NAMESPACE) { _, _, message ->
|
||||
when (JSONObject(message).optString("action")) {
|
||||
|
||||
Reference in New Issue
Block a user