Package com.castlabs.sdk.mediasession
Class MediaSessionPlugin
- java.lang.Object
-
- com.castlabs.android.Plugin
-
- com.castlabs.sdk.mediasession.MediaSessionPlugin
-
public final class MediaSessionPlugin extends Plugin
MediaSessionPlugin integrates castLabs Player SDK with AndroidX Media2 session APIs. The plugin needs to be enabled before SDK initialization:public class MyApp extends Application {@Override public void onCreate() { super.onCreate(); PlayerSDK.register(new MediaSessionPlugin()); PlayerSDK.init(getApplicationContext()); } }Registering the plugin does not create Media Session yet and the application will need to explicitly request Media Session by calling
enableMediaSession(PlayerController). Media Session is linked to thePlayerControllerand therefore the application has to providePlayerControllerinstance when enabling Media Session. The code below enables Media Session whenPlayerControlleris created:
Media Session lifecycle followspublic class SimplePlaybackDemo extends Activity {@Override protected void onCreate(Bundle savedInstanceState) { // ... PlayerView playerView = (PlayerView) findViewById(R.id.player_view); MediaSessionPlugin.enableMediaSession(playerView.getPlayerController()); // ... PlayerConfig playerConfig; // playerConfig = ... playerController.open(playerConfig); }@Override protected void onResume() { super.onResume(); // ... PlayerView playerView = (PlayerView) findViewById(R.id.player_view); MediaSessionPlugin.enableMediaSession(playerView.getPlayerController()); playerView.getLifecycleDelegate().resume(); } }PlayerController's one and is closed automatically uponPlayerController.destroy(). However, it is also possible to close Media Session explicitly:// ... PlayerView playerView = (PlayerView) findViewById(R.id.player_view); MediaSessionPlugin.disableMediaSession(playerView.getPlayerController()); // ...- Since:
- 4.2.47
-
-
Constructor Summary
Constructors Constructor Description MediaSessionPlugin()Constructs default MediaSessionPlugin
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voiddisableMediaSession(PlayerController playerController)Closes Media Sessionstatic voidenableMediaSession(PlayerController playerController)Creates and enables Media Session with default configuration.static voidenableMediaSession(PlayerController playerController, MediaSessionBuilder sessionBuilder)Creates and enables Media Session with custom configuration.StringgetId()static androidx.media2.session.MediaSessiongetMediaSession(PlayerController playerController)Gets Media Session instance e.g.static booleanisEnabled(PlayerController playerController)Checks if Media Session is enabled-
Methods inherited from class com.castlabs.android.Plugin
init, onRemotePlay
-
-
-
-
Method Detail
-
enableMediaSession
public static void enableMediaSession(@NonNull PlayerController playerController)Creates and enables Media Session with default configuration. Media Session is then linked to the providedPlayerController- Parameters:
playerController- ThePlayerControllerto link the Media Session to
-
enableMediaSession
public static void enableMediaSession(@NonNull PlayerController playerController, @Nullable MediaSessionBuilder sessionBuilder)Creates and enables Media Session with custom configuration. Media Sessionand is then linked to the providedPlayerController- Parameters:
playerController- ThePlayerControllerto link the Media Session tosessionBuilder- The session builder to customize Media Session ornullto use defaults
-
disableMediaSession
public static void disableMediaSession(@NonNull PlayerController playerController)Closes Media Session- Parameters:
playerController- ThePlayerControllerto which Media Session is linked to
-
isEnabled
public static boolean isEnabled(@NonNull PlayerController playerController)Checks if Media Session is enabled- Parameters:
playerController- ThePlayerControllerto which Media Session is linked to- Returns:
trueif Media Session is enabled andfalseotherwise
-
getMediaSession
@Nullable public static androidx.media2.session.MediaSession getMediaSession(@NonNull PlayerController playerController)Gets Media Session instance e.g. when access to Media Session Compat Token etc is needed- Parameters:
playerController- ThePlayerControllerto which Media Session is linked to- Returns:
- Media Session instance or
nullif not available
-
-