Package com.castlabs.android.player

# Class PlayerService.Binder

java.lang.Object
android.os.Binder
com.castlabs.android.player.PlayerService.Binder

All Implemented Interfaces:
  `IBinder`

Enclosing class:
  `PlayerService`

public class PlayerService.Binder extends Binder
This is the binder that will be returned by when a service connection is bound to the player service.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface android.os.IBinder

  `IBinder.DeathRecipient`

- ## Field Summary

  ### Fields inherited from interface android.os.IBinder

  `DUMP_TRANSACTION, FIRST_CALL_TRANSACTION, FLAG_ONEWAY, INTERFACE_TRANSACTION, LAST_CALL_TRANSACTION, LIKE_TRANSACTION, PING_TRANSACTION, TWEET_TRANSACTION`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Binder()`
  Creates a new Binder.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `init(IPlayerView view)`
  Initialises the service binder and eventually restores the PlayerController from the background.
  `void`
  `killBackgroundPlayer(boolean removeNotification)`
  Utility method that can be used to dispose an existing background player without connecting a `PlayerView`.
  `void`
  `release(IPlayerView playerView, boolean callDelegate)`
  Disconnects the player controller from the player view.
  `void`
  `releaseToBackground(IPlayerView playerView, int notificationId, Notification notification, boolean callDelegate)`
  Disconnect the player controller from the player view and enable background audio playback by putting the service into foreground and showing the given notification.
  `void`
  `releaseToBackground(IPlayerView playerView, int notificationId, Notification notification, boolean callDelegate, PlayerService.NotificationHandler notificationHandler)`
  Disconnect the player controller from the player view and enable background audio playback by putting the service into foreground and showing the given notification.

  ### Methods inherited from class android.os.Binder

  `attachInterface, clearCallingIdentity, clearCallingWorkSource, dump, dumpAsync, flushPendingCommands, getCallingPid, getCallingUid, getCallingUidOrThrow, getCallingUserHandle, getCallingWorkSourceUid, getInterfaceDescriptor, isBinderAlive, joinThreadPool, linkToDeath, pingBinder, queryLocalInterface, restoreCallingIdentity, restoreCallingWorkSource, setCallingWorkSourceUid, transact, unlinkToDeath`

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Binder

    public Binder()
    Creates a new Binder.

- ## Method Details

  - ### init

    public boolean init(@NonNull IPlayerView view)
    Initialises the service binder and eventually restores the PlayerController from the background. You need to call this method when the service connection is established. The passed PlayerView will the correctly initialised and loaded PlayerController after this call.

    Note to ensure that recovering playback from a background controller, please make sure that you are not interacting with the views controller before this method is called. This call might reset the views player controller.

    After calling this method, you can call `PlayerView.getPlayerController()` to get a reference to a current controller.

    Please also note that this method does recover the player controller from a background playback session, but it does not automatically resume or open a stream if no background session was found. If a call to this method returns `false`, you might want to either use the lifecycle delegate of the player view (see `PlayerView.getLifecycleDelegate()`) and call `PlayerViewLifecycleDelegate.resume()` to resume an existing session or call `PlayerController.open(Bundle)` to open a new session.
    Parameters:
      `view` - The player view
    Returns:
      True if the player controller was restored from a background controller

  - ### release

    public void release(@NonNull IPlayerView playerView, boolean callDelegate)
    Disconnects the player controller from the player view.

    If `callDelegate` is set to `true`, the views lifecycle delegate (see `PlayerView.getLifecycleDelegate()`) `PlayerViewLifecycleDelegate.releasePlayer(boolean)` will be called to fully release the controller (no background playback).
    Parameters:
      `playerView` - The player view
      `callDelegate` - If `true`, `PlayerViewLifecycleDelegate.releasePlayer(boolean)` will be called

  - ### releaseToBackground

    public void releaseToBackground(@NonNull IPlayerView playerView, int notificationId, @NonNull Notification notification, boolean callDelegate)
    Disconnect the player controller from the player view and enable background audio playback by putting the service into foreground and showing the given notification.

    If `callDelegate` is set to `true`, the views lifecycle delegate (see `PlayerView.getLifecycleDelegate()`) `PlayerViewLifecycleDelegate.releasePlayer(boolean)` will be called to fully release the controller (no background playback).
    Parameters:
      `playerView` - The player view
      `notificationId` - The notification ID (see `Service.startForeground(int, Notification)`)
      `notification` - The notification (see `Service.startForeground(int, Notification)`)
      `callDelegate` - If `true`, `PlayerViewLifecycleDelegate.releasePlayer(boolean)` will be called

  - ### releaseToBackground

    public void releaseToBackground(@NonNull IPlayerView playerView, int notificationId, @NonNull Notification notification, boolean callDelegate, @Nullable PlayerService.NotificationHandler notificationHandler)
    Disconnect the player controller from the player view and enable background audio playback by putting the service into foreground and showing the given notification.

    If `callDelegate` is set to `true`, the views lifecycle delegate (see `PlayerView.getLifecycleDelegate()`) `PlayerViewLifecycleDelegate.releasePlayer(boolean)` will be called to fully release the controller (no background playback).
    Parameters:
      `playerView` - The player view
      `notificationId` - The notification ID (see `Service.startForeground(int, Notification)`)
      `notification` - The notification (see `Service.startForeground(int, Notification)`)
      `callDelegate` - If `true`, `PlayerViewLifecycleDelegate.releasePlayer(boolean)` will be called
      `notificationHandler` - Implementation of `PlayerService.NotificationHandler` or `null`

  - ### killBackgroundPlayer

    public void killBackgroundPlayer(boolean removeNotification)
    Utility method that can be used to dispose an existing background player without connecting a `PlayerView`.

    This method can be used for example to remove the background player by clicking a button in the notification. This will dispose the background player, remove the service from the foreground, and remove the notification based on the passed parameter.
    Parameters:
      `removeNotification` - if `true`, the notification will be removed