Skip to content
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

Support Media Controls #554

Merged
merged 76 commits into from
Nov 7, 2024

Conversation

123mpozzi
Copy link
Contributor

@123mpozzi 123mpozzi commented Nov 7, 2024

Description

Introduce Media Controls support to control and display the currently-playing media information.
The info is shown in different areas of the system: in the lock-screen, within control-center, and in notifications.

Feature Overview

iOS

image image image

Android

image image

How to Configure

Currently it is only possible to enable/disable the feature, and there is no way to customize the widget.
Look at MediaControlConfig's documentation for more info.

Important

Note that the feature is enabled by default

  const player = usePlayer({
    remoteControlConfig: {
      isCastEnabled: false,
    },
+    mediaControlConfig: {
+      isEnabled: true,    // enabled by default. Put 'false' to disable
+    },
  });

Changes

Contains:

Checklist

  • 🗒 CHANGELOG entry

As I'll use a base branch and 2 separate PRs instead
To implement lock-screen controls, a player instance must be
'kept alive', so that the player is not garbage-collected or
destroyed by the system when the view is destroyed.

There are 2 ways to do this:
- init the player on the service itself
  (like in the Android SDK sample)
- init the player as usual, and somehow pass it to the service,
  to store an additional reference

This first version implements the second option.

The app has 1 strong reference, and the service has 1 strong reference
to the player. So that whenever the app dies, the background playback
still goes on.

Current Issues:
- Whenever the app gets back, the player instance should get fetched back as well!
- Another limitation with this implementation is that we're calling `setupMediaSession`
  on `player.ts`'s `inizitalize()`. But when changing sources
  (e.g. playback view, click back, playback view), the source in the
  media session does not get overridden with the source from the new view.
Via native by using player module

Note: The actual media session module can just be a native one (like offline module)
as it is just called via native (player module)
This module will be Android-only.
The old player was not getting destroyed when a
new one is being put in charge of the media session
This has to be handled via the activity lifecycle.
Took `BackgroundPlaybackScreen` from Android SDK samples as the example

Also fix `playerEventRelay` being null in some conditions
As modules represent something native that can be re-used from the
JS side, but this is not the case here
Limitation section will need an update once the lock-screen
implementation into Android SDK is finished
123mpozzi and others added 18 commits November 5, 2024 16:16
- NowPlaying info for iOS
- MediaSessions for Android
Pair-programming session w Mario

Improve general player view and player management

Fix:
- Restore the correct player from media session
- Media Session not getting destroyed
  as the `@ReactMethod onDestroy()` in `PlayerModule.kt` was nullifying the media session manager
  inside the promise block. However, the main thread was already killed from JS, so that code was
  unreached

Spot and comment a bug in `PlayerView` creation in Android SDK side
As this config is not existing on Native, we have
to set a default value directly here

Because it may not be there in the Json
@123mpozzi 123mpozzi self-assigned this Nov 7, 2024
…een-controls

Android: support Media Controls
@123mpozzi 123mpozzi marked this pull request as ready for review November 7, 2024 12:02
@123mpozzi 123mpozzi requested review from a team as code owners November 7, 2024 12:02
@123mpozzi 123mpozzi removed request for a team November 7, 2024 12:02
@123mpozzi 123mpozzi merged commit 27a72c5 into development Nov 7, 2024
9 checks passed
@123mpozzi 123mpozzi deleted the feature/base-enable-lock-screen-controls branch November 7, 2024 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant