Skip to content

Commit

Permalink
fix: android warnings uncovered player states
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Geron committed Aug 24, 2023
1 parent 2ec2243 commit 57128fa
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.pm.PackageManager
import android.net.Uri
import android.widget.FrameLayout
import com.amazonaws.ivs.player.*
import android.os.Build
import com.amazonaws.ivs.player.Player.State.*
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.LifecycleEventListener
import com.facebook.react.bridge.ReactContext
Expand Down Expand Up @@ -305,7 +305,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte
val reactContext = context as ReactContext

when (state) {
Player.State.PLAYING -> {
PLAYING -> {
if (!finishedLoading) {
val onLoadData = Arguments.createMap()
val parsedDuration = getDuration(player!!.duration);
Expand All @@ -316,7 +316,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.LOAD.toString(), onLoadData)
}
}
Player.State.READY -> {
READY -> {
val data = Arguments.createMap()
val playerData = Arguments.createMap()
playerData.putString("version", player?.version)
Expand All @@ -337,8 +337,10 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte
data.putMap("playerData", playerData)

reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.DATA.toString(), data)
}
else -> {}
};
BUFFERING -> {} // The following empty statements are intentional and avoid Kotlin’s "expression must be exhaustive" error.
IDLE -> {}
ENDED -> {}
}

val onStateChangeData = Arguments.createMap()
Expand Down Expand Up @@ -409,7 +411,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte
lastDuration = player?.duration
}
player?.position?.let { position ->
if (position > 0 && player?.state === Player.State.PLAYING) {
if (position > 0 && player?.state === PLAYING) {
onProgress(position)
}
}
Expand All @@ -421,11 +423,11 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte

private fun mapPlayerState(state: Player.State): String {
return when(state) {
Player.State.PLAYING -> "Playing"
Player.State.BUFFERING -> "Buffering"
Player.State.READY -> "Ready"
Player.State.IDLE -> "Idle"
Player.State.ENDED -> "Ended"
PLAYING -> "Playing"
BUFFERING -> "Buffering"
READY -> "Ready"
IDLE -> "Idle"
ENDED -> "Ended"
}
}

Expand Down

0 comments on commit 57128fa

Please sign in to comment.