mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-16 02:44:51 +00:00
fix(vlc): only send progress on discountinuity
This commit is contained in:
@@ -210,6 +210,16 @@ class EventMap() : HybridOmniEventMapSpec(), Player.Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onTimelineChanged(timeline: Timeline, reason: Int) {
|
||||||
|
stateListeners[NumberProperty.DURATION]?.forEach {
|
||||||
|
val duration = player.duration
|
||||||
|
it(
|
||||||
|
if (duration == C.TIME_UNSET) 0.0
|
||||||
|
else (duration.toDouble() / 1000.0).coerceAtLeast(0.0)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onTracksChanged(tracks: Tracks) {
|
override fun onTracksChanged(tracks: Tracks) {
|
||||||
selectedTrack(TRACK_TYPE_VIDEO)?.let { track ->
|
selectedTrack(TRACK_TYPE_VIDEO)?.let { track ->
|
||||||
onVideoTrackChangeListeners.forEach { it(track) }
|
onVideoTrackChangeListeners.forEach { it(track) }
|
||||||
|
|||||||
@@ -207,23 +207,9 @@ class VlcPlayer(ctx: Context) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaPlayer.Event.TimeChanged -> {
|
// progress is polled instead of pushed dozens of times per seconds.
|
||||||
notifyListeners(EVENT_POSITION_DISCONTINUITY) {
|
// this improves perf & battery life (native -> js bridge is expensive)
|
||||||
val positionMs = getCurrentPosition()
|
MediaPlayer.Event.TimeChanged -> Unit
|
||||||
val position = Player.PositionInfo(
|
|
||||||
currentMediaItemIndex,
|
|
||||||
currentMediaItemIndex,
|
|
||||||
getCurrentMediaItem(),
|
|
||||||
currentMediaItemIndex,
|
|
||||||
currentMediaItemIndex,
|
|
||||||
positionMs,
|
|
||||||
positionMs,
|
|
||||||
INDEX_UNSET,
|
|
||||||
INDEX_UNSET
|
|
||||||
)
|
|
||||||
it.onPositionDiscontinuity(position, position, DISCONTINUITY_REASON_INTERNAL)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MediaPlayer.Event.ESAdded,
|
MediaPlayer.Event.ESAdded,
|
||||||
MediaPlayer.Event.ESDeleted,
|
MediaPlayer.Event.ESDeleted,
|
||||||
@@ -491,9 +477,32 @@ class VlcPlayer(ctx: Context) :
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
player.time = positionMs.coerceAtLeast(0L).takeIf { it != TIME_UNSET } ?: 0L
|
val from = getCurrentPosition()
|
||||||
|
val target = positionMs.coerceAtLeast(0L).takeIf { it != TIME_UNSET } ?: 0L
|
||||||
|
player.time = target
|
||||||
|
// since vlc reports progress events every few ms they don't have a seek finished event.
|
||||||
|
notifyListeners(EVENT_POSITION_DISCONTINUITY) {
|
||||||
|
it.onPositionDiscontinuity(
|
||||||
|
positionInfo(from),
|
||||||
|
positionInfo(target),
|
||||||
|
DISCONTINUITY_REASON_SEEK
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun positionInfo(positionMs: Long): Player.PositionInfo =
|
||||||
|
Player.PositionInfo(
|
||||||
|
currentMediaItemIndex,
|
||||||
|
currentMediaItemIndex,
|
||||||
|
getCurrentMediaItem(),
|
||||||
|
currentMediaItemIndex,
|
||||||
|
currentMediaItemIndex,
|
||||||
|
positionMs,
|
||||||
|
positionMs,
|
||||||
|
INDEX_UNSET,
|
||||||
|
INDEX_UNSET
|
||||||
|
)
|
||||||
|
|
||||||
override fun getSeekBackIncrement(): Long = 5_000L
|
override fun getSeekBackIncrement(): Long = 5_000L
|
||||||
|
|
||||||
override fun getSeekForwardIncrement(): Long = 15_000L
|
override fun getSeekForwardIncrement(): Long = 15_000L
|
||||||
@@ -529,11 +538,20 @@ class VlcPlayer(ctx: Context) :
|
|||||||
.groupBy { listOf(it.language, it.name, it.description) }
|
.groupBy { listOf(it.language, it.name, it.description) }
|
||||||
.values.forEach { videoTracks ->
|
.values.forEach { videoTracks ->
|
||||||
val videoFormats = videoTracks.map { track ->
|
val videoFormats = videoTracks.map { track ->
|
||||||
|
val videoTrack = track as? VideoTrack
|
||||||
Format.Builder()
|
Format.Builder()
|
||||||
.setId(track.id)
|
.setId(track.id)
|
||||||
.setLabel(track.name)
|
.setLabel(track.name)
|
||||||
.setLanguage(track.language)
|
.setLanguage(track.language)
|
||||||
.setSampleMimeType("video/x-unknown")
|
.setSampleMimeType("video/x-unknown")
|
||||||
|
.setWidth(videoTrack?.width?.takeIf { it > 0 } ?: Format.NO_VALUE)
|
||||||
|
.setHeight(videoTrack?.height?.takeIf { it > 0 } ?: Format.NO_VALUE)
|
||||||
|
.setFrameRate(
|
||||||
|
videoTrack?.takeIf { it.frameRateDen > 0 }
|
||||||
|
?.let { it.frameRateNum.toFloat() / it.frameRateDen }
|
||||||
|
?: Format.NO_VALUE.toFloat()
|
||||||
|
)
|
||||||
|
.setAverageBitrate(track.bitrate.takeIf { it > 0 } ?: Format.NO_VALUE)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
val group = TrackGroup("vlc-video-${videoTracks.minOf { it.id }}", *videoFormats.toTypedArray())
|
val group = TrackGroup("vlc-video-${videoTracks.minOf { it.id }}", *videoFormats.toTypedArray())
|
||||||
|
|||||||
Reference in New Issue
Block a user