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()
-
Method Summary
All Methods Instance Methods Concrete Methods 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 aPlayerView
.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
-
-
-
-
Method Detail
-
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 callPlayerView.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 returnsfalse
, you might want to either use the lifecycle delegate of the player view (seePlayerView.getLifecycleDelegate()
) and callPlayerViewLifecycleDelegate.resume()
to resume an existing session or callPlayerController.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. IfcallDelegate
is set totrue
, the views lifecycle delegate (seePlayerView.getLifecycleDelegate()
)PlayerViewLifecycleDelegate.releasePlayer(boolean)
will be called to fully release the controller (no background playback).- Parameters:
playerView
- The player viewcallDelegate
- Iftrue
,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. IfcallDelegate
is set totrue
, the views lifecycle delegate (seePlayerView.getLifecycleDelegate()
)PlayerViewLifecycleDelegate.releasePlayer(boolean)
will be called to fully release the controller (no background playback).- Parameters:
playerView
- The player viewnotificationId
- The notification ID (seeService.startForeground(int, Notification)
)notification
- The notification (seeService.startForeground(int, Notification)
)callDelegate
- Iftrue
,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. IfcallDelegate
is set totrue
, the views lifecycle delegate (seePlayerView.getLifecycleDelegate()
)PlayerViewLifecycleDelegate.releasePlayer(boolean)
will be called to fully release the controller (no background playback).- Parameters:
playerView
- The player viewnotificationId
- The notification ID (seeService.startForeground(int, Notification)
)notification
- The notification (seeService.startForeground(int, Notification)
)callDelegate
- Iftrue
,PlayerViewLifecycleDelegate.releasePlayer(boolean)
will be callednotificationHandler
- Implementation ofPlayerService.NotificationHandler
ornull
-
killBackgroundPlayer
public void killBackgroundPlayer(boolean removeNotification)
Utility method that can be used to dispose an existing background player without connecting aPlayerView
. 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
- iftrue
, the notification will be removed
-
-