mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
Merge pull request #6762 from Bnyro/master
fix: pressing video notification when playing offline
This commit is contained in:
commit
0f40bde5b7
@ -26,6 +26,7 @@ import com.github.libretube.extensions.parcelable
|
|||||||
import com.github.libretube.extensions.toastFromMainThread
|
import com.github.libretube.extensions.toastFromMainThread
|
||||||
import com.github.libretube.extensions.updateParameters
|
import com.github.libretube.extensions.updateParameters
|
||||||
import com.github.libretube.helpers.PlayerHelper
|
import com.github.libretube.helpers.PlayerHelper
|
||||||
|
import com.github.libretube.ui.activities.MainActivity
|
||||||
import com.github.libretube.util.NowPlayingNotification
|
import com.github.libretube.util.NowPlayingNotification
|
||||||
import com.github.libretube.util.PauseableTimer
|
import com.github.libretube.util.PauseableTimer
|
||||||
import com.github.libretube.util.PlayingQueue
|
import com.github.libretube.util.PlayingQueue
|
||||||
@ -39,7 +40,7 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
|||||||
private var mediaLibrarySession: MediaLibrarySession? = null
|
private var mediaLibrarySession: MediaLibrarySession? = null
|
||||||
var exoPlayer: ExoPlayer? = null
|
var exoPlayer: ExoPlayer? = null
|
||||||
|
|
||||||
private var nowPlayingNotification: NowPlayingNotification? = null
|
private var notificationProvider: NowPlayingNotification? = null
|
||||||
var trackSelector: DefaultTrackSelector? = null
|
var trackSelector: DefaultTrackSelector? = null
|
||||||
|
|
||||||
lateinit var videoId: String
|
lateinit var videoId: String
|
||||||
@ -93,6 +94,8 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
|||||||
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
onServiceCreated(args)
|
onServiceCreated(args)
|
||||||
|
notificationProvider?.intentActivity = getIntentActivity()
|
||||||
|
|
||||||
startPlayback()
|
startPlayback()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +187,6 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
|||||||
|
|
||||||
abstract val isOfflinePlayer: Boolean
|
abstract val isOfflinePlayer: Boolean
|
||||||
abstract val isAudioOnlyPlayer: Boolean
|
abstract val isAudioOnlyPlayer: Boolean
|
||||||
abstract val intentActivity: Class<*>
|
|
||||||
|
|
||||||
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaLibrarySession? =
|
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaLibrarySession? =
|
||||||
mediaLibrarySession
|
mediaLibrarySession
|
||||||
@ -192,17 +194,18 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
val notificationProvider = NowPlayingNotification(
|
notificationProvider = NowPlayingNotification(
|
||||||
this,
|
this,
|
||||||
backgroundOnly = isAudioOnlyPlayer,
|
backgroundOnly = isAudioOnlyPlayer,
|
||||||
offlinePlayer = isOfflinePlayer,
|
offlinePlayer = isOfflinePlayer,
|
||||||
intentActivity = intentActivity
|
|
||||||
)
|
)
|
||||||
setMediaNotificationProvider(notificationProvider)
|
setMediaNotificationProvider(notificationProvider!!)
|
||||||
|
|
||||||
createPlayerAndMediaSession()
|
createPlayerAndMediaSession()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun getIntentActivity(): Class<*> = MainActivity::class.java
|
||||||
|
|
||||||
abstract suspend fun onServiceCreated(args: Bundle)
|
abstract suspend fun onServiceCreated(args: Bundle)
|
||||||
|
|
||||||
override fun onConnect(
|
override fun onConnect(
|
||||||
@ -283,7 +286,7 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
|||||||
|
|
||||||
saveWatchPosition()
|
saveWatchPosition()
|
||||||
|
|
||||||
nowPlayingNotification = null
|
notificationProvider = null
|
||||||
watchPositionTimer.destroy()
|
watchPositionTimer.destroy()
|
||||||
|
|
||||||
handler.removeCallbacksAndMessages(null)
|
handler.removeCallbacksAndMessages(null)
|
||||||
|
@ -35,8 +35,6 @@ open class OfflinePlayerService : AbstractPlayerService() {
|
|||||||
override val isOfflinePlayer: Boolean = true
|
override val isOfflinePlayer: Boolean = true
|
||||||
override val isAudioOnlyPlayer: Boolean = true
|
override val isAudioOnlyPlayer: Boolean = true
|
||||||
private var noInternetService: Boolean = false
|
private var noInternetService: Boolean = false
|
||||||
override val intentActivity: Class<*>
|
|
||||||
get() = if (noInternetService) NoInternetActivity::class.java else MainActivity::class.java
|
|
||||||
|
|
||||||
private var downloadWithItems: DownloadWithItems? = null
|
private var downloadWithItems: DownloadWithItems? = null
|
||||||
private lateinit var downloadTab: DownloadTab
|
private lateinit var downloadTab: DownloadTab
|
||||||
@ -78,6 +76,10 @@ open class OfflinePlayerService : AbstractPlayerService() {
|
|||||||
fillQueue()
|
fillQueue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getIntentActivity(): Class<*> {
|
||||||
|
return if (noInternetService) NoInternetActivity::class.java else MainActivity::class.java
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to start an audio player with the given download items
|
* Attempt to start an audio player with the given download items
|
||||||
*/
|
*/
|
||||||
|
@ -32,7 +32,6 @@ import com.github.libretube.helpers.PlayerHelper.checkForSegments
|
|||||||
import com.github.libretube.helpers.PreferenceHelper
|
import com.github.libretube.helpers.PreferenceHelper
|
||||||
import com.github.libretube.helpers.ProxyHelper
|
import com.github.libretube.helpers.ProxyHelper
|
||||||
import com.github.libretube.parcelable.PlayerData
|
import com.github.libretube.parcelable.PlayerData
|
||||||
import com.github.libretube.ui.activities.MainActivity
|
|
||||||
import com.github.libretube.util.PlayingQueue
|
import com.github.libretube.util.PlayingQueue
|
||||||
import com.github.libretube.util.YoutubeHlsPlaylistParser
|
import com.github.libretube.util.YoutubeHlsPlaylistParser
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@ -49,7 +48,6 @@ import java.util.concurrent.Executors
|
|||||||
open class OnlinePlayerService : AbstractPlayerService() {
|
open class OnlinePlayerService : AbstractPlayerService() {
|
||||||
override val isOfflinePlayer: Boolean = false
|
override val isOfflinePlayer: Boolean = false
|
||||||
override val isAudioOnlyPlayer: Boolean = true
|
override val isAudioOnlyPlayer: Boolean = true
|
||||||
override val intentActivity: Class<*> = MainActivity::class.java
|
|
||||||
|
|
||||||
// PlaylistId/ChannelId for autoplay
|
// PlaylistId/ChannelId for autoplay
|
||||||
private var playlistId: String? = null
|
private var playlistId: String? = null
|
||||||
|
@ -16,7 +16,6 @@ import android.os.Bundle
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import android.util.Log
|
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.PixelCopy
|
import android.view.PixelCopy
|
||||||
@ -326,8 +325,6 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
?.let {
|
?.let {
|
||||||
lifecycleScope.launch(Dispatchers.IO) { initializeHighlight(it) }
|
lifecycleScope.launch(Dispatchers.IO) { initializeHighlight(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.e("rec", "segments received")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,7 @@ import android.app.PendingIntent
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import androidx.core.app.PendingIntentCompat
|
import androidx.core.app.PendingIntentCompat
|
||||||
import androidx.media3.session.CommandButton
|
import androidx.media3.session.CommandButton
|
||||||
import androidx.media3.session.DefaultMediaNotificationProvider
|
import androidx.media3.session.DefaultMediaNotificationProvider
|
||||||
@ -22,9 +23,10 @@ import com.google.common.collect.ImmutableList
|
|||||||
class NowPlayingNotification(
|
class NowPlayingNotification(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val backgroundOnly: Boolean = false,
|
private val backgroundOnly: Boolean = false,
|
||||||
private val offlinePlayer: Boolean = false,
|
private val offlinePlayer: Boolean = false
|
||||||
private val intentActivity: Class<*> = MainActivity::class.java
|
|
||||||
): MediaNotification.Provider {
|
): MediaNotification.Provider {
|
||||||
|
var intentActivity: Class<*> = MainActivity::class.java
|
||||||
|
|
||||||
private val nProvider = DefaultMediaNotificationProvider.Builder(context)
|
private val nProvider = DefaultMediaNotificationProvider.Builder(context)
|
||||||
.setNotificationId(NotificationId.PLAYER_PLAYBACK.id)
|
.setNotificationId(NotificationId.PLAYER_PLAYBACK.id)
|
||||||
.setChannelId(PLAYER_CHANNEL_NAME)
|
.setChannelId(PLAYER_CHANNEL_NAME)
|
||||||
@ -44,6 +46,8 @@ class NowPlayingNotification(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.e("get intent", intentActivity.name)
|
||||||
|
|
||||||
return PendingIntentCompat
|
return PendingIntentCompat
|
||||||
.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, false)
|
.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, false)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user