Package com.jwplayer.pub.api.background
Class MediaServiceController
java.lang.Object
com.jwplayer.pub.api.background.MediaServiceController
- All Implemented Interfaces:
android.content.ServiceConnection
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected androidx.appcompat.app.AppCompatActivityprotected MediaServiceprotected Class<? extends MediaService>protected MediaSessionHelperDeprecated.protected NotificationHelperprotected ServiceMediaApi -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMediaServiceController(androidx.appcompat.app.AppCompatActivity activity, NotificationHelper notificationHelper, MediaSessionHelper mediaSessionHelper, ServiceMediaApi serviceMediaApi, Class<? extends MediaService> mediaServiceClass, BGAFactory bgaFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoidstatic MediaServiceControllerenable(androidx.appcompat.app.AppCompatActivity activity, JWPlayer player, ServiceMediaApi serviceMediaApi) Background audio in one line: builds a controller with the default notification (or withserviceMediaApi's buttons and transport behaviour, if not null), binds it now, and unbinds it whenactivityis destroyed.voidonServiceConnected(android.content.ComponentName name, android.os.IBinder service) voidonServiceDisconnected(android.content.ComponentName name) voidStops background audio.voidupdateServiceMediaApi(ServiceMediaApi serviceMediaApi) Points background audio at another player.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface android.content.ServiceConnection
onBindingDied, onNullBinding
-
Field Details
-
mMediaService
-
mActivity
protected androidx.appcompat.app.AppCompatActivity mActivity -
mNotificationHelper
-
mMediaSessionHelper
Deprecated.No longer used; the media session is owned byMediaService. -
mServiceMediaApi
-
mMediaServiceClass
-
-
Constructor Details
-
MediaServiceController
protected MediaServiceController(androidx.appcompat.app.AppCompatActivity activity, NotificationHelper notificationHelper, MediaSessionHelper mediaSessionHelper, ServiceMediaApi serviceMediaApi, Class<? extends MediaService> mediaServiceClass, BGAFactory bgaFactory)
-
-
Method Details
-
updateServiceMediaApi
Points background audio at another player. -
enable
@NonNull public static MediaServiceController enable(@NonNull androidx.appcompat.app.AppCompatActivity activity, @NonNull JWPlayer player, @Nullable ServiceMediaApi serviceMediaApi) Background audio in one line: builds a controller with the default notification (or withserviceMediaApi's buttons and transport behaviour, if not null), binds it now, and unbinds it whenactivityis destroyed.MediaServicemust still be declared in the app manifest.MediaServiceController.enable(this, player, null); // or, with custom buttons: MediaServiceController.enable(this, player, new MyServiceMediaApi(player));The controller is unbound on every
ON_DESTROY, including one caused by a configuration change, so background audio ends with the activity as it does with a manualunbindService()inonDestroy. An activity that is recreated on rotation should callenableagain inonCreate(or handle the configuration change).- Returns:
- the bound controller, for
updateServiceMediaApi(com.jwplayer.pub.api.background.ServiceMediaApi)or an earlierunbindService()
-
bindService
public void bindService() -
unbindService
public void unbindService()Stops background audio. Safe to call more than once, and before the service has connected; the controller can be bound again afterwards. -
onServiceConnected
public void onServiceConnected(android.content.ComponentName name, android.os.IBinder service) - Specified by:
onServiceConnectedin interfaceandroid.content.ServiceConnection
-
onServiceDisconnected
public void onServiceDisconnected(android.content.ComponentName name) - Specified by:
onServiceDisconnectedin interfaceandroid.content.ServiceConnection
-
MediaService.