Merge pull request #1341 from Bnyro/master

save the watch position when pausing
This commit is contained in:
Bnyro 2022-09-22 17:00:13 +02:00 committed by GitHub
commit 8c87b0238a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.Intent
import android.media.session.PlaybackState
import android.os.Build
import android.os.Handler
import android.os.IBinder
@ -20,6 +21,8 @@ import com.github.libretube.constants.BACKGROUND_CHANNEL_ID
import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.db.DatabaseHelper
import com.github.libretube.extensions.query
import com.github.libretube.extensions.toID
import com.github.libretube.util.AutoPlayHelper
import com.github.libretube.util.NowPlayingNotification
@ -221,6 +224,14 @@ class BackgroundMode : Service() {
Player.STATE_IDLE -> {
onDestroy()
}
PlaybackState.STATE_PAUSED -> {
query {
DatabaseHelper.saveWatchPosition(
videoId,
player?.currentPosition ?: 0L
)
}
}
Player.STATE_BUFFERING -> {}
Player.STATE_READY -> {}
}

View File

@ -51,6 +51,7 @@ import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.await
import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.hideKeyboard
import com.github.libretube.extensions.query
import com.github.libretube.extensions.toID
import com.github.libretube.interfaces.PlayerOptionsInterface
import com.github.libretube.models.PlayerViewModel
@ -1012,6 +1013,16 @@ class PlayerFragment : BaseFragment() {
binding.playImageView.setImageResource(R.drawable.ic_play)
}
// save the watch position when paused
if (playbackState == PlaybackState.STATE_PAUSED) {
query {
DatabaseHelper.saveWatchPosition(
videoId!!,
exoPlayer.currentPosition
)
}
}
// listen for the stop button in the notification
if (playbackState == PlaybackState.STATE_STOPPED) {
// finish PiP by finishing the activity