mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +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.updateParameters
|
||||
import com.github.libretube.helpers.PlayerHelper
|
||||
import com.github.libretube.ui.activities.MainActivity
|
||||
import com.github.libretube.util.NowPlayingNotification
|
||||
import com.github.libretube.util.PauseableTimer
|
||||
import com.github.libretube.util.PlayingQueue
|
||||
@ -39,7 +40,7 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
||||
private var mediaLibrarySession: MediaLibrarySession? = null
|
||||
var exoPlayer: ExoPlayer? = null
|
||||
|
||||
private var nowPlayingNotification: NowPlayingNotification? = null
|
||||
private var notificationProvider: NowPlayingNotification? = null
|
||||
var trackSelector: DefaultTrackSelector? = null
|
||||
|
||||
lateinit var videoId: String
|
||||
@ -93,6 +94,8 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
onServiceCreated(args)
|
||||
notificationProvider?.intentActivity = getIntentActivity()
|
||||
|
||||
startPlayback()
|
||||
}
|
||||
|
||||
@ -184,7 +187,6 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
||||
|
||||
abstract val isOfflinePlayer: Boolean
|
||||
abstract val isAudioOnlyPlayer: Boolean
|
||||
abstract val intentActivity: Class<*>
|
||||
|
||||
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaLibrarySession? =
|
||||
mediaLibrarySession
|
||||
@ -192,17 +194,18 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
val notificationProvider = NowPlayingNotification(
|
||||
notificationProvider = NowPlayingNotification(
|
||||
this,
|
||||
backgroundOnly = isAudioOnlyPlayer,
|
||||
offlinePlayer = isOfflinePlayer,
|
||||
intentActivity = intentActivity
|
||||
)
|
||||
setMediaNotificationProvider(notificationProvider)
|
||||
setMediaNotificationProvider(notificationProvider!!)
|
||||
|
||||
createPlayerAndMediaSession()
|
||||
}
|
||||
|
||||
open fun getIntentActivity(): Class<*> = MainActivity::class.java
|
||||
|
||||
abstract suspend fun onServiceCreated(args: Bundle)
|
||||
|
||||
override fun onConnect(
|
||||
@ -283,7 +286,7 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
||||
|
||||
saveWatchPosition()
|
||||
|
||||
nowPlayingNotification = null
|
||||
notificationProvider = null
|
||||
watchPositionTimer.destroy()
|
||||
|
||||
handler.removeCallbacksAndMessages(null)
|
||||
|
@ -35,8 +35,6 @@ open class OfflinePlayerService : AbstractPlayerService() {
|
||||
override val isOfflinePlayer: Boolean = true
|
||||
override val isAudioOnlyPlayer: Boolean = true
|
||||
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 lateinit var downloadTab: DownloadTab
|
||||
@ -78,6 +76,10 @@ open class OfflinePlayerService : AbstractPlayerService() {
|
||||
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
|
||||
*/
|
||||
|
@ -32,7 +32,6 @@ import com.github.libretube.helpers.PlayerHelper.checkForSegments
|
||||
import com.github.libretube.helpers.PreferenceHelper
|
||||
import com.github.libretube.helpers.ProxyHelper
|
||||
import com.github.libretube.parcelable.PlayerData
|
||||
import com.github.libretube.ui.activities.MainActivity
|
||||
import com.github.libretube.util.PlayingQueue
|
||||
import com.github.libretube.util.YoutubeHlsPlaylistParser
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@ -49,7 +48,6 @@ import java.util.concurrent.Executors
|
||||
open class OnlinePlayerService : AbstractPlayerService() {
|
||||
override val isOfflinePlayer: Boolean = false
|
||||
override val isAudioOnlyPlayer: Boolean = true
|
||||
override val intentActivity: Class<*> = MainActivity::class.java
|
||||
|
||||
// PlaylistId/ChannelId for autoplay
|
||||
private var playlistId: String? = null
|
||||
|
@ -16,7 +16,6 @@ import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.PowerManager
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.PixelCopy
|
||||
@ -326,8 +325,6 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
?.let {
|
||||
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.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.core.app.PendingIntentCompat
|
||||
import androidx.media3.session.CommandButton
|
||||
import androidx.media3.session.DefaultMediaNotificationProvider
|
||||
@ -22,9 +23,10 @@ import com.google.common.collect.ImmutableList
|
||||
class NowPlayingNotification(
|
||||
private val context: Context,
|
||||
private val backgroundOnly: Boolean = false,
|
||||
private val offlinePlayer: Boolean = false,
|
||||
private val intentActivity: Class<*> = MainActivity::class.java
|
||||
private val offlinePlayer: Boolean = false
|
||||
): MediaNotification.Provider {
|
||||
var intentActivity: Class<*> = MainActivity::class.java
|
||||
|
||||
private val nProvider = DefaultMediaNotificationProvider.Builder(context)
|
||||
.setNotificationId(NotificationId.PLAYER_PLAYBACK.id)
|
||||
.setChannelId(PLAYER_CHANNEL_NAME)
|
||||
@ -44,6 +46,8 @@ class NowPlayingNotification(
|
||||
}
|
||||
}
|
||||
|
||||
Log.e("get intent", intentActivity.name)
|
||||
|
||||
return PendingIntentCompat
|
||||
.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, false)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user