Package com.castlabs.android.player
Class PlayerViewLifecycleDelegate
- java.lang.Object
-
- com.castlabs.android.player.PlayerViewLifecycleDelegate
-
public class PlayerViewLifecycleDelegate extends Object
The default lifecycle delegate. This class provides life cycle callbacks that can be used to manage the life cycle of the player controller in the context of an Activity that shows aIPlayerView. The defaultPlayerViewexposes this through thePlayerView.getLifecycleDelegate()method. Use this to hook up activity lifecycle events. Note that thePlayerViewLifecycleDelegatedoes not handle the use-case when the Activity is completely destroyed and re-created with the subsequent `onCreate` call. To handle this the application may want to store the playback state upon `onSaveInstanceState` and use the state in `onCreate` call, for more details see thePlayerView
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfacePlayerViewLifecycleDelegate.LifecycleListenerCallback to receive delegated Lifecycle events.static classPlayerViewLifecycleDelegate.ResumeConfigurationConfiguration object which will dictate the behaviour of thePlayerControllerwhenever the enclosing
-
Field Summary
Fields Modifier and Type Field Description static PlayerViewLifecycleDelegate.ResumeConfigurationDEFAULT_RESUME_CONFIGURATION
-
Constructor Summary
Constructors Constructor Description PlayerViewLifecycleDelegate(IPlayerView playerView)Create a new instance using the given player view
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLifecycleListener(PlayerViewLifecycleDelegate.LifecycleListener lifecycleListener)Adds a lifecycle delegate listenervoidreleasePlayer(boolean background_playback)Call this method when the hosting activity stops.voidremoveLifecycleListener(PlayerViewLifecycleDelegate.LifecycleListener lifecycleListener)voidresume()Call this method when the hosting activity resumes.voidsetResumeConfiguration(PlayerViewLifecycleDelegate.ResumeConfiguration resumeConfiguration)voidstart(Activity activity)Call this method when the hosting activity is started.
-
-
-
Field Detail
-
DEFAULT_RESUME_CONFIGURATION
public static final PlayerViewLifecycleDelegate.ResumeConfiguration DEFAULT_RESUME_CONFIGURATION
-
-
Constructor Detail
-
PlayerViewLifecycleDelegate
public PlayerViewLifecycleDelegate(@NonNull IPlayerView playerView)Create a new instance using the given player view- Parameters:
playerView- The player view
-
-
Method Detail
-
start
public void start(@NonNull Activity activity)Call this method when the hosting activity is started. This method sets up the devices screen to be kept on for the current Activity by setting the window flagFLAG_KEEP_SCREEN_ON. If you don't want to enforce this behaviour, consider clearing the window flags after a call to this method and then manually handle the flag. If you do clear the window settings, please ensure that you set theFLAG_KEEP_SCREEN_ONflag at least while playback is running usinggetWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);. Usually one would overwrite the activityActivity.onStartmethod and delegate the event:@Override protected void onStart() { super.onStart(); playerView.getLifecycleDelegate().start(this); }- Parameters:
activity- The Activity that hosts the player view
-
resume
public void resume()
Call this method when the hosting activity resumes. This method resumes playback from a saved state whenreleasePlayer(boolean)was called before and player state was saved. Note that the playback of a saved state is only resumed if the current player controller is not running in background (seePlayerController.isBackgrounded()). Usually one would overwrite the activitiesActivity.onResume()method and delegate the event:
Please note that you should not call this method directly in the activities@Override protected void onResume() { super.onResume(); playerView.getLifecycleDelegate().resume(); }onResume()callback if you are using aPlayerService. In that case, useonResume()to (re)connect to the service and depending on the state of the service, call this method when the service is connected.
-
releasePlayer
public void releasePlayer(boolean background_playback)
Call this method when the hosting activity stops. The method saves the player state so playback can be resumed later, when the user navigates back to the activity. Ifbackground_playbackistrue, the player controller will not be destroyed and should be handed off to thePlayerServiceto resume it from there later. Ifbackground_playbackisfalse, the player controller will be destroyed usingPlayerController.destroy(). Usually one would overwrite the activitiesActivity.onStop()method and delegate the event:@Override protected void onStop() { super.onStop(); playerView.getLifecycleDelegate().releasePlayer(false); }- Parameters:
background_playback- True if the player will be send to background
-
addLifecycleListener
public void addLifecycleListener(@NonNull PlayerViewLifecycleDelegate.LifecycleListener lifecycleListener)Adds a lifecycle delegate listener- Parameters:
lifecycleListener- The listener
-
removeLifecycleListener
public void removeLifecycleListener(@NonNull PlayerViewLifecycleDelegate.LifecycleListener lifecycleListener)- Parameters:
lifecycleListener- the Listener
-
setResumeConfiguration
public void setResumeConfiguration(@NonNull PlayerViewLifecycleDelegate.ResumeConfiguration resumeConfiguration)Sets thePlayerViewLifecycleDelegate.ResumeConfiguration.This configuration is used whenever
resume()is called.- Parameters:
resumeConfiguration- the configuration to set
-
-