Fixes video stream position for live streams.
This commit is contained in:
+15
-7
@@ -86,6 +86,8 @@ class MultiPlayerPlaybackManager(
|
|||||||
applicationContext: Context,
|
applicationContext: Context,
|
||||||
): MediaSession {
|
): MediaSession {
|
||||||
val existingSession = playingMap.get(id) ?: cache.get(id)
|
val existingSession = playingMap.get(id) ?: cache.get(id)
|
||||||
|
// avoids saving positions for live streams otherwise caching goes crazy
|
||||||
|
val mustCachePositions = !uri.contains(".m3u8", true)
|
||||||
if (existingSession != null) return existingSession
|
if (existingSession != null) return existingSession
|
||||||
|
|
||||||
val player =
|
val player =
|
||||||
@@ -115,7 +117,9 @@ class MultiPlayerPlaybackManager(
|
|||||||
playingMap.put(id, mediaSession)
|
playingMap.put(id, mediaSession)
|
||||||
} else {
|
} else {
|
||||||
player.setWakeMode(C.WAKE_MODE_NONE)
|
player.setWakeMode(C.WAKE_MODE_NONE)
|
||||||
cachedPositions.add(uri, player.currentPosition)
|
if (mustCachePositions) {
|
||||||
|
cachedPositions.add(uri, player.currentPosition)
|
||||||
|
}
|
||||||
cache.put(id, mediaSession)
|
cache.put(id, mediaSession)
|
||||||
playingMap.remove(id, mediaSession)
|
playingMap.remove(id, mediaSession)
|
||||||
}
|
}
|
||||||
@@ -125,20 +129,22 @@ class MultiPlayerPlaybackManager(
|
|||||||
when (playbackState) {
|
when (playbackState) {
|
||||||
STATE_IDLE -> {
|
STATE_IDLE -> {
|
||||||
// only saves if it wqs playing
|
// only saves if it wqs playing
|
||||||
if (abs(player.currentPosition) > 1) {
|
if (mustCachePositions && abs(player.currentPosition) > 1) {
|
||||||
cachedPositions.add(uri, player.currentPosition)
|
cachedPositions.add(uri, player.currentPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
STATE_READY -> {
|
STATE_READY -> {
|
||||||
cachedPositions.get(uri)?.let { lastPosition ->
|
if (mustCachePositions) {
|
||||||
if (abs(player.currentPosition - lastPosition) > 5 * 60) {
|
cachedPositions.get(uri)?.let { lastPosition ->
|
||||||
player.seekTo(lastPosition)
|
if (abs(player.currentPosition - lastPosition) > 5 * 60) {
|
||||||
|
player.seekTo(lastPosition)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
// only saves if it wqs playing
|
// only saves if it wqs playing
|
||||||
if (abs(player.currentPosition) > 1) {
|
if (mustCachePositions && abs(player.currentPosition) > 1) {
|
||||||
cachedPositions.add(uri, player.currentPosition)
|
cachedPositions.add(uri, player.currentPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,7 +156,9 @@ class MultiPlayerPlaybackManager(
|
|||||||
newPosition: PositionInfo,
|
newPosition: PositionInfo,
|
||||||
reason: Int,
|
reason: Int,
|
||||||
) {
|
) {
|
||||||
cachedPositions.add(uri, newPosition.positionMs)
|
if (mustCachePositions) {
|
||||||
|
cachedPositions.add(uri, newPosition.positionMs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user