Monday, 24 May 2021

Exoplayer notification not clearing

I have exoplayer integrated within my application based on this link.

I have added a pending intent inside createCurrentContentIntent().

    return PendingIntent.getActivity(
        context, 0,
        Intent(context, MyActivity::class.java), 0
    )

I face an issue over here. I started playing the audio and the player notification also comes up in the status bar. My requirement is to play audio even if the app is in the background. So, I haven't released the player in onStop(). I have added the below code in onDestroy().

    override fun onDestroy() {
        playerNotificationManager?.setPlayer(null)
        player?.stop()
        player?.release()
        player = null
        super.onDestroy()
    }

If I manually kill the application from the background when the player is playing, the notification doesn't go off. So, if I click on the notification it will crash with NullPointerException because MyActivtity is no more.

Could someone suggest a solution for the same?



from Exoplayer notification not clearing

No comments:

Post a Comment