mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
Merge pull request #7044 from Bnyro/master
fix: watch position not set for downloaded videos
This commit is contained in:
commit
a5ef88ad1a
@ -5,6 +5,7 @@ import android.os.Bundle
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
|
import androidx.annotation.CallSuper
|
||||||
import androidx.annotation.OptIn
|
import androidx.annotation.OptIn
|
||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
@ -51,7 +52,8 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
|||||||
lateinit var videoId: String
|
lateinit var videoId: String
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var isTransitioning = true
|
var isTransitioning = false
|
||||||
|
private set
|
||||||
|
|
||||||
val handler = Handler(Looper.getMainLooper())
|
val handler = Handler(Looper.getMainLooper())
|
||||||
|
|
||||||
@ -88,6 +90,14 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPlaybackStateChanged(playbackState: Int) {
|
||||||
|
super.onPlaybackStateChanged(playbackState)
|
||||||
|
|
||||||
|
if (playbackState == Player.STATE_READY) {
|
||||||
|
isTransitioning = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCustomCommand(
|
override fun onCustomCommand(
|
||||||
@ -311,7 +321,10 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
|||||||
*
|
*
|
||||||
* This function should base its actions on the videoId variable.
|
* This function should base its actions on the videoId variable.
|
||||||
*/
|
*/
|
||||||
abstract suspend fun startPlayback()
|
@CallSuper
|
||||||
|
open suspend fun startPlayback() {
|
||||||
|
isTransitioning = true
|
||||||
|
}
|
||||||
|
|
||||||
private fun saveWatchPosition() {
|
private fun saveWatchPosition() {
|
||||||
if (isTransitioning || !watchPositionsEnabled) return
|
if (isTransitioning || !watchPositionsEnabled) return
|
||||||
|
@ -90,6 +90,8 @@ open class OfflinePlayerService : AbstractPlayerService() {
|
|||||||
* Attempt to start an audio player with the given download items
|
* Attempt to start an audio player with the given download items
|
||||||
*/
|
*/
|
||||||
override suspend fun startPlayback() {
|
override suspend fun startPlayback() {
|
||||||
|
super.startPlayback()
|
||||||
|
|
||||||
val downloadWithItems = withContext(Dispatchers.IO) {
|
val downloadWithItems = withContext(Dispatchers.IO) {
|
||||||
Database.downloadDao().findById(videoId)
|
Database.downloadDao().findById(videoId)
|
||||||
}!!
|
}!!
|
||||||
|
@ -77,8 +77,6 @@ open class OnlinePlayerService : AbstractPlayerService() {
|
|||||||
|
|
||||||
Player.STATE_BUFFERING -> {}
|
Player.STATE_BUFFERING -> {}
|
||||||
Player.STATE_READY -> {
|
Player.STATE_READY -> {
|
||||||
isTransitioning = false
|
|
||||||
|
|
||||||
// save video to watch history when the video starts playing or is being resumed
|
// save video to watch history when the video starts playing or is being resumed
|
||||||
// waiting for the player to be ready since the video can't be claimed to be watched
|
// waiting for the player to be ready since the video can't be claimed to be watched
|
||||||
// while it did not yet start actually, but did buffer only so far
|
// while it did not yet start actually, but did buffer only so far
|
||||||
@ -113,11 +111,11 @@ open class OnlinePlayerService : AbstractPlayerService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun startPlayback() {
|
override suspend fun startPlayback() {
|
||||||
|
super.startPlayback()
|
||||||
|
|
||||||
val timestamp = startTimestamp ?: 0L
|
val timestamp = startTimestamp ?: 0L
|
||||||
startTimestamp = null
|
startTimestamp = null
|
||||||
|
|
||||||
isTransitioning = true
|
|
||||||
|
|
||||||
streams = withContext(Dispatchers.IO) {
|
streams = withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
StreamsExtractor.extractStreams(videoId)
|
StreamsExtractor.extractStreams(videoId)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user