mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Merge pull request #1341 from Bnyro/master
save the watch position when pausing
This commit is contained in:
commit
8c87b0238a
@ -5,6 +5,7 @@ import android.app.NotificationChannel
|
|||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.media.session.PlaybackState
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.IBinder
|
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.IntentData
|
||||||
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
|
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
|
||||||
import com.github.libretube.constants.PreferenceKeys
|
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.extensions.toID
|
||||||
import com.github.libretube.util.AutoPlayHelper
|
import com.github.libretube.util.AutoPlayHelper
|
||||||
import com.github.libretube.util.NowPlayingNotification
|
import com.github.libretube.util.NowPlayingNotification
|
||||||
@ -221,6 +224,14 @@ class BackgroundMode : Service() {
|
|||||||
Player.STATE_IDLE -> {
|
Player.STATE_IDLE -> {
|
||||||
onDestroy()
|
onDestroy()
|
||||||
}
|
}
|
||||||
|
PlaybackState.STATE_PAUSED -> {
|
||||||
|
query {
|
||||||
|
DatabaseHelper.saveWatchPosition(
|
||||||
|
videoId,
|
||||||
|
player?.currentPosition ?: 0L
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Player.STATE_BUFFERING -> {}
|
Player.STATE_BUFFERING -> {}
|
||||||
Player.STATE_READY -> {}
|
Player.STATE_READY -> {}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ import com.github.libretube.extensions.TAG
|
|||||||
import com.github.libretube.extensions.await
|
import com.github.libretube.extensions.await
|
||||||
import com.github.libretube.extensions.formatShort
|
import com.github.libretube.extensions.formatShort
|
||||||
import com.github.libretube.extensions.hideKeyboard
|
import com.github.libretube.extensions.hideKeyboard
|
||||||
|
import com.github.libretube.extensions.query
|
||||||
import com.github.libretube.extensions.toID
|
import com.github.libretube.extensions.toID
|
||||||
import com.github.libretube.interfaces.PlayerOptionsInterface
|
import com.github.libretube.interfaces.PlayerOptionsInterface
|
||||||
import com.github.libretube.models.PlayerViewModel
|
import com.github.libretube.models.PlayerViewModel
|
||||||
@ -1012,6 +1013,16 @@ class PlayerFragment : BaseFragment() {
|
|||||||
binding.playImageView.setImageResource(R.drawable.ic_play)
|
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
|
// listen for the stop button in the notification
|
||||||
if (playbackState == PlaybackState.STATE_STOPPED) {
|
if (playbackState == PlaybackState.STATE_STOPPED) {
|
||||||
// finish PiP by finishing the activity
|
// finish PiP by finishing the activity
|
||||||
|
Loading…
Reference in New Issue
Block a user