Now Playing
***********
The Now Playing feature provides convenient player control from both
the Control Center and the Lock Screen, available on Android and iOS
devices. This functionality is implemented as a separate plugin, which
must be installed and enabled.
Setup
=====
First, install the "@castlabs/react-native-prestoplay-now-playing"
package:
npm install @castlabs/react-native-prestoplay-now-playing
Once the plugin is installed, enable it when initializing the SDK, by
passing the "NowPlayingPlugin"
(https://players.castlabs.com/react-native/1.4.2/docs/now-playing-plugin-api/classes/NowPlayingPlugin/)
class. For example:
import { Sdk } from "@castlabs/react-native-prestoplay";
import { NowPlayingPlugin } from "@castlabs/react-native-prestoplay-now-playing";
Sdk.initialize({
licenseKey: {
/* Valid license here */
},
plugins: [NowPlayingPlugin],
});
Android
-------
Add extra permissions and initialize the "CustomMediaSessionService"
service in the "./android/app/src/main/AndroidManifest.xml" file:
iOS
---
Initialize an audio session in the "./ios//AppDelegate.mm"
file:
#import
//...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive:true error:nil];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
Finally, enable background audio by adding the following snippet to
the "./ios//Info.plist" file:
UIBackgroundModes
audio
Usage
=====
The Now Playing feature is enabled by default. To improve the user
experience, a title and artwork can be added to the player
configuration. For example:
const playerConfiguration = {
autoPlay: true,
source: {
url: "https://demo.cf.castlabs.com/media/prestohls/master.m3u8",
type: ContentType.Dash,
},
metaData: {
title: "Big Buck Bunny",
artist: "Blender Foundation",
artworkUrl: "",
},
};
To disable the Now Playing feature, set "nowPlaying.enabled" to
"false" in the player configuration. For example:
const playerConfiguration = {
autoPlay: true,
source: {
url: "https://demo.cf.castlabs.com/media/prestohls/master.m3u8",
type: ContentType.Dash,
},
nowPlaying: {
enabled: false,
},
};
Chapters
========
Using the Chapters metadata section, it's possible to define bookmarks
in the timeline. The "Next Item" and "Previous Item" buttons will show
up in the media controls
const playerConfiguration = {
metaData: {
chapterInfo: [
{startTimeMs: 0, title: 'Chapter 1'},
{startTimeMs: 60 * 1000, title: 'Chapter 2'},
{startTimeMs: 120 * 1000, title: 'Chapter 3'},
],
},
};
Next / Previous media controls
==============================
The "Go to Next Item" and "Go to Previous Item" media controls adapt
to what is defined for the current content — chapters (see above), a
playlist, or both:
+-----------------------------------+-----------------------------------+-----------------------------------+
| Chapters | Playlist | Behavior of the controls |
|===================================|===================================|===================================|
| ✓ | ✗ | Navigate between chapters |
+-----------------------------------+-----------------------------------+-----------------------------------+
| ✗ | ✓ | Navigate between playlist items |
+-----------------------------------+-----------------------------------+-----------------------------------+
| ✓ | ✓ | Navigate between chapters. "Next" |
| | | on the last chapter advances to |
| | | the next playlist item |
+-----------------------------------+-----------------------------------+-----------------------------------+
| ✗ | ✗ | The controls are not shown |
+-----------------------------------+-----------------------------------+-----------------------------------+