Skip to content

Commit

Permalink
feat: android send position message when position changed (#387)
Browse files Browse the repository at this point in the history
* chore: android send position message when position changed

* chore: bump version
  • Loading branch information
NormanWangEndeavor authored Nov 29, 2024
1 parent 626939f commit 7403189
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,12 @@ public void onPlayerEvent(DorisPlayerEvent playerEvent) {
}

switch (playerEvent.event) {
case POSITION_CHANGED:
dorisMessaging.onProgressChanged(
playerEvent.details.currentPosition,
playerEvent.details.duration,
playerEvent.details.windowStartTimeMs
);
case TRACK_INFO_CHANGED:
if (selectUserPreferredTrack) {
selectUserPreferredTrack = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ class DorisMessaging(
}

private fun seekTo(message: DiceMessage.SetPlayerPositionMessage) {
val windowStartTime = player.windowStartTime
val oldPosition = player.currentPosition
val newPosition = message.getSeekPosition(player.windowStartTime)
player.seekTo(newPosition)
sendPlayerSeekedMessage(oldPosition, newPosition)
sendPlayerProgressMessage(message, newPosition)
sendPlayerProgressMessage(
request = message,
currentPosition = newPosition,
duration = player.duration,
windowStartTime = windowStartTime
)
}

private fun DiceMessage.SetPlayerPositionMessage.getSeekPosition(windowStartTimeMs: Long): Long {
Expand Down Expand Up @@ -167,7 +173,16 @@ class DorisMessaging(
}
}

fun onProgressChanged(currentPosition: Long) = sendPlayerProgressMessage(request = null, currentPosition = currentPosition)
fun onProgressChanged(
currentPosition: Long,
duration: Long,
windowStartTime: Long
) = sendPlayerProgressMessage(
request = null,
currentPosition = currentPosition,
duration = duration,
windowStartTime = windowStartTime,
)

override fun onPlaybackStateChanged(playbackState: Int) {
if (playbackState == Player.STATE_READY) {
Expand Down Expand Up @@ -302,8 +317,12 @@ class DorisMessaging(
)
)

private fun sendPlayerProgressMessage(request: DiceMessage?, currentPosition: Long) {
val duration = player.duration
private fun sendPlayerProgressMessage(
request: DiceMessage?,
currentPosition: Long,
duration: Long,
windowStartTime: Long,
) {
val isOnLiveEdge = if (isLive) isOnLiveEdge(currentPosition, duration) else null
sendMessage(
DiceMessage.PlayerProgressMessage(
Expand All @@ -312,7 +331,9 @@ class DorisMessaging(
type = streamType,
isAtLiveEdge = isOnLiveEdge,
progress = getProgress(currentPosition),
dateTime = null,
currentPosition = currentPosition,
duration = duration,
windowStartTime = windowStartTime,
),
requestMessageId = request?.messageId
)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-video",
"version": "7.5.36",
"version": "7.5.37",
"dorisAndroidVersion": "3.11.10",
"description": "A <Video /> element for react-native",
"main": "Video.tsx",
Expand Down

0 comments on commit 7403189

Please sign in to comment.