public class SimpleVideoPlayer
extends java.lang.Object
NOTE: If you want to get a video player up and running with minimal effort, just instantiate this class and call play();
Constructor and Description |
---|
SimpleVideoPlayer(android.app.Activity activity,
android.widget.FrameLayout container,
Video video,
java.lang.String videoTitle,
boolean autoplay) |
SimpleVideoPlayer(android.app.Activity activity,
android.widget.FrameLayout container,
Video video,
java.lang.String videoTitle,
boolean autoplay,
int startPostitionMs,
PlaybackControlLayer.FullscreenCallback fullscreenCallback) |
Modifier and Type | Method and Description |
---|---|
void |
addActionButton(android.graphics.drawable.Drawable icon,
java.lang.String contentDescription,
android.view.View.OnClickListener onClickListener)
Creates a button to put in the top right of the video player.
|
void |
addPlaybackListener(ExoplayerWrapper.PlaybackListener listener)
Set a listener which reacts to state changes, video size changes, and errors.
|
void |
disableSeeking()
Hides the seek bar thumb and prevents the user from seeking to different time points in the
video.
|
void |
enableSeeking()
Makes the seek bar thumb visible and allows the user to seek to different time points in the
video.
|
int |
getCurrentPosition()
Returns the current playback position in milliseconds.
|
int |
getDuration()
Returns the duration of the track in milliseconds or
ExoPlayer.UNKNOWN_TIME if the duration is unknown. |
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 |
moveSurfaceToBackground()
When mutliple surface layers are used (ex.
|
void |
moveSurfaceToForeground()
When mutliple surface layers are used (ex.
|
void |
pause()
Pause video playback.
|
void |
play()
Resume video playback.
|
void |
release()
When you are finished using this
SimpleVideoPlayer , make sure to call this method. |
void |
setChromeColor(int color)
Sets the color of the top chrome, bottom chrome, and background.
|
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 |
setLogoImage(android.graphics.drawable.Drawable logo)
Set the logo with appears in the left of the top chrome.
|
void |
setPlaybackControlColor(int color)
Sets the color of the buttons and seek bar.
|
void |
setPlayCallback(PlaybackControlLayer.PlayCallback playCallback)
Set the callback which will be called when the player plays video.
|
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 |
showTopChrome()
Shows the top chrome (which displays the logo, title, and action buttons).
|
public SimpleVideoPlayer(android.app.Activity activity, android.widget.FrameLayout container, Video video, java.lang.String videoTitle, boolean autoplay)
activity
- The activity that will contain the video player.container
- The FrameLayout
which will contain the video player.video
- The video that should be played.videoTitle
- The title of the video (displayed on the left of the top chrome).autoplay
- Whether the video should start playing immediately.public SimpleVideoPlayer(android.app.Activity activity, android.widget.FrameLayout container, Video video, java.lang.String videoTitle, boolean autoplay, int startPostitionMs, PlaybackControlLayer.FullscreenCallback fullscreenCallback)
activity
- The activity that will contain the video player.container
- The FrameLayout
which will contain the video player.video
- The video that should be played.videoTitle
- The title of the video (displayed on the left of the top chrome).autoplay
- Whether the video should start playing immediately.fullscreenCallback
- The callback which gets triggered when the player enters or leaves
fullscreen mode.public void addActionButton(android.graphics.drawable.Drawable icon, java.lang.String contentDescription, android.view.View.OnClickListener onClickListener)
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 void addPlaybackListener(ExoplayerWrapper.PlaybackListener listener)
listener
- Listens to playback events.public void disableSeeking()
public void enableSeeking()
public int getCurrentPosition()
public int getDuration()
ExoPlayer.UNKNOWN_TIME
if the duration is unknown.public void hide()
LayerManager
's
container.public void hideTopChrome()
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 moveSurfaceToBackground()
public void moveSurfaceToForeground()
public void pause()
public void play()
public void setChromeColor(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 setPlayCallback(PlaybackControlLayer.PlayCallback playCallback)
playCallback
- The callback.public void setLogoImage(android.graphics.drawable.Drawable logo)
logo
- The drawable which will be the logo.public void setPlaybackControlColor(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 setVideoTitle(java.lang.String title)
title
- The video title. If it is too long, it will be ellipsized.public boolean shouldBePlaying()
public void show()
public void showTopChrome()
public void release()
SimpleVideoPlayer
, make sure to call this method.