fix player notificatoin not showing up when restarting exoplayer
This commit is contained in:
parent
4de5568b7b
commit
f80e4c8e5f
|
@ -78,4 +78,5 @@ interface NewPlayer {
|
|||
fun selectChapter(index: Int)
|
||||
fun playStream(item: String, streamVariant: String, playMode: PlayMode)
|
||||
fun release()
|
||||
fun getItemLinkOfMediaItem(mediaItem: MediaItem) : String
|
||||
}
|
||||
|
|
|
@ -279,8 +279,14 @@ class NewPlayerImpl(
|
|||
mutableExoPlayer.update {
|
||||
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) {
|
||||
if (exoPlayer.value?.playbackState == Player.STATE_IDLE || exoPlayer.value == null) {
|
||||
prepare()
|
||||
|
@ -313,7 +319,6 @@ class NewPlayerImpl(
|
|||
|
||||
private suspend
|
||||
fun toMediaItem(item: String): MediaItem {
|
||||
|
||||
val availableStream = repository.getAvailableStreamVariants(item)
|
||||
var selectedStream = availableStream[availableStream.size / 2]
|
||||
for (preferredStream in preferredStreamVariants) {
|
||||
|
|
|
@ -47,7 +47,7 @@ private const val TAG = "NewPlayerService"
|
|||
@AndroidEntryPoint
|
||||
class NewPlayerService : MediaSessionService() {
|
||||
|
||||
private lateinit var mediaSession: MediaSession
|
||||
private var mediaSession: MediaSession? = null
|
||||
private lateinit var customCommands: List<CustomCommand>
|
||||
|
||||
@Inject
|
||||
|
@ -89,7 +89,7 @@ class NewPlayerService : MediaSessionService() {
|
|||
controller: MediaSession.ControllerInfo
|
||||
) {
|
||||
super.onPostConnect(session, controller)
|
||||
mediaSession.setCustomLayout(customCommands.map { it.commandButton })
|
||||
mediaSession?.setCustomLayout(customCommands.map { it.commandButton })
|
||||
}
|
||||
|
||||
override fun onCustomCommand(
|
||||
|
@ -130,7 +130,7 @@ class NewPlayerService : MediaSessionService() {
|
|||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
newPlayer.release()
|
||||
mediaSession.release()
|
||||
mediaSession?.release()
|
||||
}
|
||||
|
||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||
|
|
Loading…
Reference in New Issue