public class PlaybackControlLayer extends java.lang.Object implements Layer, PlayerControlCallback
Layer
that creates a customizable view for controlling video playback.
The view consists of:
1) a top chrome which contains a logo, title, and set of action buttons.
2) a bottom chrome which contains a seek bar, fullscreen button, and text views indicating the current time and total duration of the video.
3) a translucent middle section which displays a pause/play button.
The view appears when the container containing the PlaybackControlLayer
is tapped. It
automatically disappears after a given time.
The view can be customized by:
1) Setting the color of the top chrome, bottom chrome, and background - this is called the chrome tint color.
2) Setting the color of the text - this is called the text color.
3) Setting the color of the buttons and seek bar - this is called the control tint color.
4) Setting the logo image displayed in the left of the top chrome.
5) Setting the title of the video displayed in the left of the top chrome (and to the right of the logo).
6) Adding an action button by providing an image, a content description, and a click handler. If there is enough room, the action buttons will be displayed on the right of the top chrome. If there is NOT enough room, an overflow button will be displayed. When the overflow button is clicked, a dialog box listing the content descriptions for the action buttons is displayed. The action is then triggered by selecting it from the dialog box.
The view is defined in the layout file: res/layout/playback_control_layer.xml.
Modifier and Type | Class and Description |
---|---|
static interface |
PlaybackControlLayer.FullscreenCallback
In order to imbue the
PlaybackControlLayer with the ability make the player fullscreen,
a PlaybackControlLayer.FullscreenCallback must be assigned to it. |
static interface |
PlaybackControlLayer.PlayCallback
The
PlaybackControlLayer.PlayCallback implementation will be called when the player
plays the video (e.g. |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CHROME_COLOR
The chrome (the top chrome, bottom chrome, and background) is by default a slightly
transparent black.
|
static int |
DEFAULT_CONTROL_TINT_COLOR
By default, there is no tint to the controls.
|
static int |
DEFAULT_TEXT_COLOR
By default, the text is white.
|
Constructor and Description |
---|
PlaybackControlLayer(java.lang.String videoTitle) |
PlaybackControlLayer(java.lang.String videoTitle,
PlaybackControlLayer.FullscreenCallback fullscreenCallback) |
Modifier and Type | Method and Description |
---|---|
void |
addActionButton(android.app.Activity activity,
android.graphics.drawable.Drawable icon,
java.lang.String contentDescription,
android.view.View.OnClickListener onClickListener)
Creates a button to put in the set of action buttons at the right of the top chrome.
|
android.widget.FrameLayout |
createView(LayerManager layerManager)
Builds and sets up the view that will be layered onto the video player.
|
void |
disableSeeking()
Hides the seek bar thumb and prevents the user from seeking to different time points in the
video.
|
void |
doToggleFullscreen()
Fullscreen mode will rotate to landscape mode, hide the action bar, hide the navigation bar,
hide the system tray, and make the video player take up the full size of the display.
|
void |
enableSeeking()
Makes the seek bar thumb visible and allows the user to seek to different time points in the
video.
|
LayerManager |
getLayerManager()
Returns the
LayerManager which is responsible for displaying this layer's view. |
void |
hide()
Fades the playback control layer out and then removes it from the
LayerManager 's
container. |
void |
hideTopChrome()
Hides the top chrome (which displays the logo, title, and action buttons).
|
boolean |
isFullscreen()
Returns whether the player is currently in fullscreen mode.
|
void |
onLayerDisplayed(LayerManager layerManager)
Called when a Layer's view has been displayed on the screen.
|
void |
onPause()
Updates the play/pause button to the play icon.
|
void |
onPlay()
Updates the play/pause button to the pause icon.
|
void |
setChromeColor(int color)
Sets the color of the top chrome, bottom chrome, and background.
|
void |
setControlColor(int color)
Sets the color of the buttons and seek bar.
|
void |
setFullscreen(boolean shouldBeFullscreen)
Make the player enter or leave fullscreen mode.
|
void |
setFullscreenCallback(PlaybackControlLayer.FullscreenCallback fullscreenCallback)
Set the callback which will be called when the player enters and leaves fullscreen mode.
|
void |
setLogoImageView(android.graphics.drawable.Drawable logo)
Set the logo with appears in the left of the top chrome.
|
void |
setPlayCallback(PlaybackControlLayer.PlayCallback playCallback)
Set play callback
|
void |
setPlayPause(boolean shouldPlay)
Play or pause the player.
|
void |
setSeekbarColor(int color)
Sets the color of the seekbar.
|
void |
setTextColor(int color)
Sets the color of the text views
|
void |
setVideoTitle(java.lang.String title)
Set the title of the video in the left of the top chrome (to the right of the logo).
|
boolean |
shouldBePlaying()
Returns whether the player should be playing (based on whether the user has
tapped pause or play).
|
void |
show()
Add the playback control layer back to the container.
|
void |
show(int timeout)
Add the playback control layer back to the container.
|
void |
showTopChrome()
Shows the top chrome (which displays the logo, title, and action buttons).
|
java.lang.String |
stringForTime(int timeMs)
Format the milliseconds to HH:MM:SS or MM:SS format.
|
void |
togglePlayPause()
If the player is paused, play it and if the player is playing, pause it.
|
void |
updateActionButtons()
The action buttons are displayed in the top right of the video player.
|
void |
updateColors()
Ensure that the chrome, control, and text colors displayed on the screen are correct.
|
void |
updatePlayPauseButton()
Change the icon of the play/pause button to indicate play or pause based on the state of the
video player.
|
int |
updateProgress()
Adjust the position of the action bar to reflect the progress of the video.
|
public static final int DEFAULT_CHROME_COLOR
public static final int DEFAULT_CONTROL_TINT_COLOR
public static final int DEFAULT_TEXT_COLOR
public PlaybackControlLayer(java.lang.String videoTitle)
public PlaybackControlLayer(java.lang.String videoTitle, PlaybackControlLayer.FullscreenCallback fullscreenCallback)
public void addActionButton(android.app.Activity activity, android.graphics.drawable.Drawable icon, java.lang.String contentDescription, android.view.View.OnClickListener onClickListener)
activity
- The activity that contains the video player.icon
- The image of the action (ex. trash can).contentDescription
- The text description this action. This is used in case the
action buttons do not fit in the video player. If so, an overflow
button will appear and, when clicked, it will display a list of the
content descriptions for each action.onClickListener
- The handler for when the action is triggered.public android.widget.FrameLayout createView(LayerManager layerManager)
Layer
FrameLayout
to ensure that the LayerManager
can overlay it on top
of the other layers.createView
in interface Layer
layerManager
- The LayerManager
which will contain this layer.LayerManager
public void disableSeeking()
public void doToggleFullscreen()
1) Inside the android manifest, the activity that uses the video player has the attribute android:configChanges="orientation".
2) Other views in the activity (or fragment) are hidden (or made visible) when this method is called.
public void enableSeeking()
public LayerManager getLayerManager()
LayerManager
which is responsible for displaying this layer's view.public void hide()
LayerManager
's
container.public void show(int timeout)
timeout
- Hide the view after timeout milliseconds. If timeout == 0, then the playback
controls will not disappear unless their container is tapped again.public void show()
public void hideTopChrome()
public void showTopChrome()
public boolean isFullscreen()
public void setFullscreen(boolean shouldBeFullscreen)
shouldBeFullscreen
- If true, the player is put into fullscreen mode. If false, the player
leaves fullscreen mode.public void onLayerDisplayed(LayerManager layerManager)
Layer
onLayerDisplayed
in interface Layer
layerManager
- The LayerManager
which will contain this layer.public void onPause()
onPause
in interface PlayerControlCallback
public void onPlay()
onPlay
in interface PlayerControlCallback
public void setChromeColor(int color)
color
- a color derived from the @{link Color} class (ex. Color.RED
).public void setControlColor(int color)
color
- a color derived from the @{link Color} class (ex. Color.RED
).public void setSeekbarColor(int color)
color
- a color derived from the @{link Color} class (ex. Color.RED
).public void setTextColor(int color)
color
- a color derived from the @{link Color} class (ex. Color.RED
).public void setFullscreenCallback(PlaybackControlLayer.FullscreenCallback fullscreenCallback)
fullscreenCallback
- The callback should hide other views in the activity when the player
enters fullscreen mode and show other views when the player leaves
fullscreen mode.public void setLogoImageView(android.graphics.drawable.Drawable logo)
logo
- The drawable which will be the logo.public void setPlayPause(boolean shouldPlay)
shouldPlay
- If true, then the player starts playing. If false, the player pauses.public void setVideoTitle(java.lang.String title)
title
- The video title. If it is too long, it will be ellipsized.public boolean shouldBePlaying()
public java.lang.String stringForTime(int timeMs)
public void togglePlayPause()
public void updateActionButtons()
public void updateColors()
public void updatePlayPauseButton()
public int updateProgress()
public void setPlayCallback(PlaybackControlLayer.PlayCallback playCallback)