-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intercept notification events #40
Conversation
* | ||
* For this observable to send events, set [interceptPlayerActionsTriggeredExternally][com.doublesymmetry.kotlinaudio.models.PlayerConfig.interceptPlayerActionsTriggeredExternally] to true. | ||
*/ | ||
var onPlayerActionTriggeredExternally = _onPlayerActionTriggeredExternally.asSharedFlow() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can now opt in to have the player actions be intercepted. For RNTP this will be true
by default, but since KA is used as a general audio library, it's good to have the option.
|
||
mediaSession.isActive = true | ||
|
||
notificationManager = NotificationManager(context, exoPlayer, mediaSession.sessionToken, notificationEventHolder) | ||
val playerToUse = if (playerConfig.interceptPlayerActionsTriggeredExternally) forwardingPlayer else exoPlayer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on the flag, we can choose to intercept(forward) Player actions via ForwardingPlayer
. This will intercept(forward) actions triggered by the media session and notification.
private fun createForwardingPlayer(): ForwardingPlayer { | ||
return object : ForwardingPlayer(exoPlayer) { | ||
override fun play() { | ||
playerEventHolder.updateOnMediaSessionCallbackTriggered(MediaSessionCallback.PLAY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If ForwardingPlayer
is used, the player actions will trigger our custom player events.
@@ -443,34 +477,4 @@ abstract class BaseAudioPlayer internal constructor(private val context: Context | |||
) | |||
} | |||
} | |||
|
|||
inner class MediaSessionListener : MediaSessionCompat.Callback() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to explicitly override media session events, since our ForwardingPlayer
already intercepts events sent by both media session and notification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
This PR enables notification events to be intercepted. Conveniently, this also intercepts media session events without any additional code.
RNTP also needs a PR to use this, coming soonTM.