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 28, 2023
1 parent 2ec2243 commit 60639ea
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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 +306,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 +317,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 +338,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 +412,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 +424,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 60639ea

Please sign in to comment.