Class MediaServiceController

java.lang.Object
com.jwplayer.pub.api.background.MediaServiceController
All Implemented Interfaces:
android.content.ServiceConnection

public class MediaServiceController extends Object implements android.content.ServiceConnection
  • Field Details

  • Constructor Details

  • Method Details

    • updateServiceMediaApi

      public void updateServiceMediaApi(@NonNull ServiceMediaApi serviceMediaApi)
      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 with serviceMediaApi's buttons and transport behaviour, if not null), binds it now, and unbinds it when activity is destroyed. MediaService must 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 manual unbindService() in onDestroy. An activity that is recreated on rotation should call enable again in onCreate (or handle the configuration change).

      Returns:
      the bound controller, for updateServiceMediaApi(com.jwplayer.pub.api.background.ServiceMediaApi) or an earlier unbindService()
    • 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:
      onServiceConnected in interface android.content.ServiceConnection
    • onServiceDisconnected

      public void onServiceDisconnected(android.content.ComponentName name)
      Specified by:
      onServiceDisconnected in interface android.content.ServiceConnection