fix player notificatoin not showing up when restarting exoplayer

This commit is contained in:
Christian Schabesberger 2024-09-11 17:23:27 +02:00
parent 4de5568b7b
commit f80e4c8e5f
3 changed files with 10 additions and 4 deletions

View File

@ -78,4 +78,5 @@ interface NewPlayer {
fun selectChapter(index: Int) fun selectChapter(index: Int)
fun playStream(item: String, streamVariant: String, playMode: PlayMode) fun playStream(item: String, streamVariant: String, playMode: PlayMode)
fun release() fun release()
fun getItemLinkOfMediaItem(mediaItem: MediaItem) : String
} }

View File

@ -279,8 +279,14 @@ class NewPlayerImpl(
mutableExoPlayer.update { mutableExoPlayer.update {
null null
} }
mediaController = null
uniqueIdToIdLookup = HashMap()
} }
override fun getItemLinkOfMediaItem(mediaItem: MediaItem) =
uniqueIdToIdLookup[mediaItem.mediaId.toLong()]
?: throw NewPlayerException("Could not find Media item with mediaId: ${mediaItem.mediaId}")
private fun internalPlayStream(mediaItem: MediaItem, playMode: PlayMode) { private fun internalPlayStream(mediaItem: MediaItem, playMode: PlayMode) {
if (exoPlayer.value?.playbackState == Player.STATE_IDLE || exoPlayer.value == null) { if (exoPlayer.value?.playbackState == Player.STATE_IDLE || exoPlayer.value == null) {
prepare() prepare()
@ -313,7 +319,6 @@ class NewPlayerImpl(
private suspend private suspend
fun toMediaItem(item: String): MediaItem { fun toMediaItem(item: String): MediaItem {
val availableStream = repository.getAvailableStreamVariants(item) val availableStream = repository.getAvailableStreamVariants(item)
var selectedStream = availableStream[availableStream.size / 2] var selectedStream = availableStream[availableStream.size / 2]
for (preferredStream in preferredStreamVariants) { for (preferredStream in preferredStreamVariants) {

View File

@ -47,7 +47,7 @@ private const val TAG = "NewPlayerService"
@AndroidEntryPoint @AndroidEntryPoint
class NewPlayerService : MediaSessionService() { class NewPlayerService : MediaSessionService() {
private lateinit var mediaSession: MediaSession private var mediaSession: MediaSession? = null
private lateinit var customCommands: List<CustomCommand> private lateinit var customCommands: List<CustomCommand>
@Inject @Inject
@ -89,7 +89,7 @@ class NewPlayerService : MediaSessionService() {
controller: MediaSession.ControllerInfo controller: MediaSession.ControllerInfo
) { ) {
super.onPostConnect(session, controller) super.onPostConnect(session, controller)
mediaSession.setCustomLayout(customCommands.map { it.commandButton }) mediaSession?.setCustomLayout(customCommands.map { it.commandButton })
} }
override fun onCustomCommand( override fun onCustomCommand(
@ -130,7 +130,7 @@ class NewPlayerService : MediaSessionService() {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
newPlayer.release() newPlayer.release()
mediaSession.release() mediaSession?.release()
} }
override fun onTaskRemoved(rootIntent: Intent?) { override fun onTaskRemoved(rootIntent: Intent?) {