-
Notifications
You must be signed in to change notification settings - Fork 13
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
Android: mediaSession - support simple background playback as well #542
Android: mediaSession - support simple background playback as well #542
Conversation
<service | ||
android:name="com.bitmovin.player.reactnative.services.BackgroundPlaybackService" | ||
android:foregroundServiceType="mediaPlayback" | ||
android:exported="true"> | ||
</service> | ||
|
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.
Note
This is also essential for properly updating the PlayerView
after the app has been minimized. In fact, lifecycle changes alone don’t seem to be sufficient without this, as the entire PlayerView
may otherwise appear black when the app is re-opened.
isBackgroundPlaybackEnabled = if (isMediaSessionPlaybackEnabled) { | ||
isMediaSessionPlaybackEnabled | ||
} else { | ||
playerConfigJson?.getMap("playbackConfig")?.getBoolean("isBackgroundPlaybackEnabled") ?: false | ||
} |
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.
Open Question about Config Design
Currently, I am making the media session flag forcibly treat the background flag as true when enabled, but that still has to be decided.
This way makes sense for me since media-session is a form of background-playback.
import android.os.IBinder | ||
import com.bitmovin.player.api.Player | ||
import com.bitmovin.player.api.media.session.MediaSession | ||
import com.bitmovin.player.api.media.session.MediaSessionService | ||
import com.bitmovin.player.reactnative.PlayerServiceBinder | ||
|
||
class MediaSessionPlaybackService : MediaSessionService() { |
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.
Open Question about Services Design
Unfortunately, I don't see a clean way of unifying the two services (maybe someone more proficient in Kotlin can help tho 🙏 )
I see mainly 2 drawbacks when unifying the services:
- a media session is always initialized in
onCreate
. Even if I pass data via the intent,onBind
will be called afteronCreate
from my understanding, so the 'fake' media session is already created - here we inherit from
MediaSessionService()
. This is not necessary for simple background-playback. Simple backgorund playback, on the other hand, only needsService()
, without the additional wrappers
@@ -52,3 +57,5 @@ class MediaSessionConnectionManager(val context: ReactApplicationContext) { | |||
playerModule: PlayerModule? = context.playerModule, | |||
): Player = playerModule?.getPlayerOrNull(nativeId) ?: throw IllegalArgumentException("Invalid PlayerId $nativeId") | |||
} | |||
|
|||
open class PlayerServiceBinder(open var player: Player?) : Binder() |
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.
I am not sure if this is the best way for extending Binder()
for our use-case. I would like input here from someone more knowledgeable in Kotlin 🙏
…re/android-extend-mediasession-for-simple-bg-playback # Conflicts: # android/src/main/java/com/bitmovin/player/reactnative/BackgroundPlaybackManager.kt
d534946
into
feature/android-enable-lock-screen-controls
Description
As of the current integration, background playback is only supported through media session.
This PR allows to run playback in the background without having to create any media session.
Related work
#541 implements background-playback independently from media session.
Since media session is a subset of background playback, the idea is to unify and re-use most of the logic
Changes
Checklist
CHANGELOG
entry