mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
fix crash when removing notification
This commit is contained in:
parent
47fccb760a
commit
499c629923
@ -9,7 +9,6 @@ import android.os.Build
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.util.Log
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
@ -21,7 +20,6 @@ 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.DatabaseHolder
|
|
||||||
import com.github.libretube.db.DatabaseHolder.Companion.Database
|
import com.github.libretube.db.DatabaseHolder.Companion.Database
|
||||||
import com.github.libretube.db.obj.WatchPosition
|
import com.github.libretube.db.obj.WatchPosition
|
||||||
import com.github.libretube.extensions.awaitQuery
|
import com.github.libretube.extensions.awaitQuery
|
||||||
@ -117,7 +115,7 @@ class BackgroundMode : Service() {
|
|||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
try {
|
try {
|
||||||
// clear the playing queue
|
// clear the playing queue
|
||||||
PlayingQueue.clear()
|
PlayingQueue.resetToDefaults()
|
||||||
|
|
||||||
// get the intent arguments
|
// get the intent arguments
|
||||||
videoId = intent?.getStringExtra(IntentData.videoId)!!
|
videoId = intent?.getStringExtra(IntentData.videoId)!!
|
||||||
@ -201,9 +199,8 @@ class BackgroundMode : Service() {
|
|||||||
} else if (PlayerHelper.watchPositionsEnabled) {
|
} else if (PlayerHelper.watchPositionsEnabled) {
|
||||||
try {
|
try {
|
||||||
val watchPosition = awaitQuery {
|
val watchPosition = awaitQuery {
|
||||||
DatabaseHolder.Database.watchPositionDao().findById(videoId)
|
Database.watchPositionDao().findById(videoId)
|
||||||
}
|
}
|
||||||
Log.e("position", watchPosition.toString())
|
|
||||||
streams?.duration?.let {
|
streams?.duration?.let {
|
||||||
if (watchPosition != null && watchPosition.position < it * 1000 * 0.9) {
|
if (watchPosition != null && watchPosition.position < it * 1000 * 0.9) {
|
||||||
player?.seekTo(watchPosition.position)
|
player?.seekTo(watchPosition.position)
|
||||||
@ -355,7 +352,7 @@ class BackgroundMode : Service() {
|
|||||||
*/
|
*/
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
// clear the playing queue
|
// clear the playing queue
|
||||||
PlayingQueue.clear()
|
PlayingQueue.resetToDefaults()
|
||||||
|
|
||||||
if (this::nowPlayingNotification.isInitialized) nowPlayingNotification.destroySelfAndPlayer()
|
if (this::nowPlayingNotification.isInitialized) nowPlayingNotification.destroySelfAndPlayer()
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
context?.hideKeyboard(view)
|
context?.hideKeyboard(view)
|
||||||
|
|
||||||
// clear the playing queue
|
// clear the playing queue
|
||||||
PlayingQueue.clear()
|
PlayingQueue.resetToDefaults()
|
||||||
|
|
||||||
changeOrientationMode()
|
changeOrientationMode()
|
||||||
|
|
||||||
@ -502,7 +502,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
try {
|
try {
|
||||||
// clear the playing queue
|
// clear the playing queue
|
||||||
PlayingQueue.clear()
|
|
||||||
PlayingQueue.resetToDefaults()
|
PlayingQueue.resetToDefaults()
|
||||||
|
|
||||||
saveWatchPosition()
|
saveWatchPosition()
|
||||||
@ -849,8 +848,9 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
|
|
||||||
// save the watch position when paused
|
// save the watch position when paused
|
||||||
if (playbackState == PlaybackState.STATE_PAUSED) {
|
if (playbackState == PlaybackState.STATE_PAUSED) {
|
||||||
|
val watchPosition = WatchPosition(videoId!!, exoPlayer.currentPosition)
|
||||||
query {
|
query {
|
||||||
Database.watchPositionDao().insertAll(WatchPosition(videoId!!, exoPlayer.currentPosition))
|
Database.watchPositionDao().insertAll(watchPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,17 +213,17 @@ class NowPlayingNotification(
|
|||||||
* Destroy the [NowPlayingNotification]
|
* Destroy the [NowPlayingNotification]
|
||||||
*/
|
*/
|
||||||
fun destroySelfAndPlayer() {
|
fun destroySelfAndPlayer() {
|
||||||
|
playerNotification?.setPlayer(null)
|
||||||
|
|
||||||
mediaSession.isActive = false
|
mediaSession.isActive = false
|
||||||
mediaSession.release()
|
mediaSession.release()
|
||||||
mediaSessionConnector.setPlayer(null)
|
|
||||||
playerNotification?.setPlayer(null)
|
player.stop()
|
||||||
|
player.release()
|
||||||
|
|
||||||
val notificationManager = context.getSystemService(
|
val notificationManager = context.getSystemService(
|
||||||
Context.NOTIFICATION_SERVICE
|
Context.NOTIFICATION_SERVICE
|
||||||
) as NotificationManager
|
) as NotificationManager
|
||||||
notificationManager.cancel(PLAYER_NOTIFICATION_ID)
|
notificationManager.cancel(PLAYER_NOTIFICATION_ID)
|
||||||
|
|
||||||
player.stop()
|
|
||||||
player.release()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,8 +61,6 @@ object PlayingQueue {
|
|||||||
|
|
||||||
fun isEmpty() = queue.isEmpty()
|
fun isEmpty() = queue.isEmpty()
|
||||||
|
|
||||||
fun clear() = queue.clear()
|
|
||||||
|
|
||||||
fun size() = queue.size
|
fun size() = queue.size
|
||||||
|
|
||||||
fun currentIndex(): Int {
|
fun currentIndex(): Int {
|
||||||
@ -139,5 +137,6 @@ object PlayingQueue {
|
|||||||
fun resetToDefaults() {
|
fun resetToDefaults() {
|
||||||
repeatQueue = false
|
repeatQueue = false
|
||||||
onQueueTapListener = {}
|
onQueueTapListener = {}
|
||||||
|
queue.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user