public class EMVideoView
extends RelativeLayout
implements com.google.android.exoplayer.audio.AudioCapabilitiesReceiver.Listener
To an external user this view should have the same APIs used with the standard VideoView to help with quick implementations.
Modifier and Type | Class and Description |
---|---|
static class |
EMVideoView.TouchVideoView
Since the default Android VideoView will consume the touch events
without calling super
|
static class |
EMVideoView.VideoType |
Modifier and Type | Field and Description |
---|---|
protected DefaultControls |
defaultControls |
protected Repeater |
pollRepeater |
Constructor and Description |
---|
EMVideoView(Context context) |
EMVideoView(Context context,
AttributeSet attrs) |
EMVideoView(Context context,
AttributeSet attrs,
int defStyleAttr) |
EMVideoView(Context context,
AttributeSet attrs,
int defStyleAttr,
int defStyleRes) |
Modifier and Type | Method and Description |
---|---|
void |
addExoPlayerListener(ExoPlayerListener listener)
Sets the listener to inform of any exoPlayer events
|
int |
getBufferPercentage()
Retrieves the current buffer percent of the video.
|
long |
getCurrentPosition()
Retrieves the current position of the audio playback.
|
long |
getDuration()
Retrieves the duration of the current audio item.
|
ImageView |
getPreviewImageView()
Gets the preview ImageView for use with image loading libraries.
|
java.lang.String |
getUserAgent()
Retrieves the user agent that the EMVideoView will use when communicating
with media servers
|
Uri |
getVideoUri()
Retrieves the current Video URI.
|
boolean |
isPlaying()
Returns if a video is currently in playback
|
void |
onAudioCapabilitiesChanged(com.google.android.exoplayer.audio.AudioCapabilities audioCapabilities) |
protected void |
onDetachedFromWindow() |
void |
overrideDuration(int duration)
Setting this will override the duration that the item may actually be.
|
void |
overridePosition(boolean override)
Sets if the audio position should be overridden, allowing the time to be restarted at will.
|
void |
pause()
If a video is currently in playback, it will be paused and the progressPoll
will be stopped (see
startProgressPoll(EMEventBus) ) |
void |
release()
Stops the playback and releases all resources attached to this
EMVideoView.
|
void |
removeExoPlayerListener(ExoPlayerListener listener)
Removes the specified listener for the ExoPlayer.
|
void |
reset()
Stops the current video playback and resets the listener states
so that we receive the callbacks for events like onPrepared
|
void |
restartOverridePosition()
Restarts the audio position to the start if the position is being overridden (see
overridePosition(boolean) ). |
void |
seekTo(int milliSeconds)
Moves the current video progress to the specified location.
|
void |
setBus(EMEventBus bus)
Sets the bus to use for dispatching Events that correspond to the callbacks
listed in
EMVideoViewControlsCallback |
void |
setDefaultControlsEnabled(boolean enabled)
Enables and disables the media control overlay for the video view
|
void |
setFastForwardButtonEnabled(boolean enabled)
Sets the button state for the Fast Forward button on the default controls; see
setDefaultControlsEnabled(boolean) . |
void |
setFastForwardButtonRemoved(boolean removed)
Adds or removes the Fast Forward button.
|
void |
setFastForwardImageResource(int resourceId)
Sets the state list drawable resource id to use for the Fast Forward button.
|
void |
setNextButtonEnabled(boolean enabled)
Sets the button state for the Next button on the default controls; see
setDefaultControlsEnabled(boolean) . |
void |
setNextButtonRemoved(boolean removed)
Adds or removes the Next button.
|
void |
setNextImageResource(int resourceId)
Sets the state list drawable resource id to use for the Next button.
|
void |
setOnCompletionListener(MediaPlayer.OnCompletionListener listener)
Sets the listener to inform of VideoPlayer completion events.
|
void |
setOnErrorListener(MediaPlayer.OnErrorListener listener)
Sets the listener to inform of playback errors.
|
void |
setOnInfoListener(MediaPlayer.OnInfoListener listener)
Sets the listener to inform of media information events.
|
void |
setOnPreparedListener(MediaPlayer.OnPreparedListener listener)
Sets the listener to inform of VideoPlayer prepared events.
|
void |
setOnTouchListener(OnTouchListener listener) |
void |
setPlayPauseImages(int playResourceId,
int pauseResourceId)
Sets the resource id's to use for the PlayPause button.
|
void |
setPositionOffset(int offset)
Sets the amount of time to change the return value from
getCurrentPosition() . |
void |
setPreviewImage(Bitmap bitmap)
Sets an image that will be visible only when the video is loading.
|
void |
setPreviewImage(Drawable drawable)
Sets an image that will be visible only when the video is loading.
|
void |
setPreviewImage(Uri uri)
Sets an image that will be visible only when the video is loading.
|
void |
setPreviousButtonEnabled(boolean enabled)
Sets the button state for the Previous button on the default controls; see
setDefaultControlsEnabled(boolean) . |
void |
setPreviousButtonRemoved(boolean removed)
Adds or removes the Previous button.
|
void |
setPreviousImageResource(int resourceId)
Sets the state list drawable resource id to use for the Previous button.
|
void |
setProgressPollDelay(int milliSeconds)
Sets the delay to use when notifying of progress.
|
void |
setReleaseOnDetachFromWindow(boolean releaseOnDetach)
WARNING: Use of this method may cause memory leaks.
|
void |
setRewindButtonEnabled(boolean enabled)
Sets the button state for the Rewind button on the default controls; see
setDefaultControlsEnabled(boolean) . |
void |
setRewindButtonRemoved(boolean removed)
Adds or removes the Rewind button.
|
void |
setRewindImageResource(int resourceId)
Sets the state list drawable resource id to use for the Rewind button.
|
void |
setShutterColor(int color)
Sets the color for the video shutters (the black bars above and below the video)
|
void |
setVideoPath(java.lang.String path)
Sets the path to the video.
|
void |
setVideoURI(Uri uri)
Sets the Uri location for the video to play.
|
void |
setVideoURI(Uri uri,
MediaUtil.MediaType defaultMediaType)
Sets the Uri location for the video to play
|
void |
setVideoViewControlsCallback(EMVideoViewControlsCallback callback)
Sets the EMVideoViewControlsCallback to be used.
|
boolean |
setVolume(float volume)
Sets the volume level for devices that support
the ExoPlayer (JellyBean or greater).
|
void |
showDefaultControls()
Requests the DefaultControls to become visible.
|
void |
start()
Starts the playback for the video specified in
#setVideoURI(android.net.Uri)
or setVideoPath(String) . |
void |
startProgressPoll()
Starts the progress poll.
|
void |
startProgressPoll(EMEventBus bus)
Starts the progress poll.
|
void |
startProgressPoll(EMProgressCallback callback)
Starts the progress poll with the callback to be informed of the progress
events.
|
void |
stopPlayback()
If a video is currently in playback then the playback will be stopped
and the progressPoll will be stopped (see
startProgressPoll() ) |
void |
stopProgressPoll()
Stops the progress poll
(see
startProgressPoll() ) |
void |
suspend()
If a video is currently in playback then the playback will be suspended and
and the progressPoll will be stopped (see
startProgressPoll() ) |
protected DefaultControls defaultControls
protected Repeater pollRepeater
public EMVideoView(Context context)
public EMVideoView(Context context, AttributeSet attrs)
public EMVideoView(Context context, AttributeSet attrs, int defStyleAttr)
public EMVideoView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
protected void onDetachedFromWindow()
public void setOnTouchListener(OnTouchListener listener)
public void onAudioCapabilitiesChanged(com.google.android.exoplayer.audio.AudioCapabilities audioCapabilities)
onAudioCapabilitiesChanged
in interface com.google.android.exoplayer.audio.AudioCapabilitiesReceiver.Listener
public void setReleaseOnDetachFromWindow(boolean releaseOnDetach)
Enables or disables the automatic release when the EMVideoView is detached
from the window. Normally this is expected to release all resources used
by calling release()
. If releaseOnDetach
is disabled
then release()
will need to be manually called.
releaseOnDetach
- False to disable the automatic release in onDetachedFromWindow()
public void release()
setReleaseOnDetachFromWindow(boolean)
has been set.public java.lang.String getUserAgent()
public void setPreviewImage(Drawable drawable)
drawable
- The drawable to use for the preview imagepublic void setPreviewImage(Bitmap bitmap)
bitmap
- The bitmap to use for the preview imagepublic void setPreviewImage(Uri uri)
uri
- The Uri pointing to the preview imagepublic ImageView getPreviewImageView()
public void setShutterColor(int color)
color
- The colorpublic void setProgressPollDelay(int milliSeconds)
milliSeconds
- The millisecond delay to usepublic void setBus(EMEventBus bus)
EMVideoViewControlsCallback
bus
- The EventBus to dispatch events onpublic void startProgressPoll(EMEventBus bus)
setBus(EMEventBus)
then
you should use the startProgressPoll()
method instead.bus
- The EventBus event dispatcher that the listener is connected topublic void startProgressPoll(EMProgressCallback callback)
callback
- The Callback to inform of progress eventspublic void startProgressPoll()
setBus(EMEventBus)
or previously called startProgressPoll(EMEventBus)
, otherwise you won't get notified
of progress changespublic void stopProgressPoll()
startProgressPoll()
)public void setDefaultControlsEnabled(boolean enabled)
enabled
- Weather the default video controls are enabled (default: false)public void showDefaultControls()
setDefaultControlsEnabled(boolean)
.public void setPreviousButtonEnabled(boolean enabled)
setDefaultControlsEnabled(boolean)
.
setDefaultControlsEnabled(boolean)
must be called prior to this.
This will just change the images specified with setPreviousImageResource(int)
,
or use the defaults if they haven't been set, and block any click events.
This method will NOT re-add buttons that have previously been removed with
setPreviousButtonRemoved(boolean)
.
enabled
- If the Previous button is enabled [default: false]public void setNextButtonEnabled(boolean enabled)
setDefaultControlsEnabled(boolean)
.
setDefaultControlsEnabled(boolean)
must be called prior to this.
This will just change the images specified with setNextImageResource(int)
,
or use the defaults if they haven't been set, and block any click events.
This method will NOT re-add buttons that have previously been removed with
setNextButtonRemoved(boolean)
.
enabled
- If the Next button is enabled [default: false]public void setRewindButtonEnabled(boolean enabled)
setDefaultControlsEnabled(boolean)
.
setDefaultControlsEnabled(boolean)
must be called prior to this.
This will just change the images specified with setRewindImageResource(int)
,
or use the defaults if they haven't been set, and block any click events.
This method will NOT re-add buttons that have previously been removed with
setRewindButtonRemoved(boolean)
.
enabled
- If the Rewind button is enabled [default: false]public void setFastForwardButtonEnabled(boolean enabled)
setDefaultControlsEnabled(boolean)
.
setDefaultControlsEnabled(boolean)
must be called prior to this.
This will just change the images specified with setFastForwardImageResource(int)
,
or use the defaults if they haven't been set, and block any click events.
This method will NOT re-add buttons that have previously been removed with
setFastForwardButtonRemoved(boolean)
.
enabled
- If the Fast Forward button is enabled [default: false]public void setVideoViewControlsCallback(EMVideoViewControlsCallback callback)
setDefaultControlsEnabled(boolean)
must
be called prior to this.callback
- The EMVideoViewControlsCallback to usepublic void setPlayPauseImages(@DrawableRes int playResourceId, @DrawableRes int pauseResourceId)
setDefaultControlsEnabled(boolean)
must
be called prior to this.playResourceId
- The resourceId or 0pauseResourceId
- The resourceId or 0public void setPreviousImageResource(@DrawableRes int resourceId)
setDefaultControlsEnabled(boolean)
must be called prior to this.resourceId
- The resourceId or 0public void setNextImageResource(@DrawableRes int resourceId)
setDefaultControlsEnabled(boolean)
must be called prior to this.resourceId
- The resourceId or 0public void setRewindImageResource(@DrawableRes int resourceId)
setDefaultControlsEnabled(boolean)
must be called prior to this.resourceId
- The resourceId or 0public void setFastForwardImageResource(@DrawableRes int resourceId)
setDefaultControlsEnabled(boolean)
must be called prior to this.resourceId
- The resourceId or 0public void setPreviousButtonRemoved(boolean removed)
setPreviousButtonEnabled(boolean)
setDefaultControlsEnabled(boolean)
must be called prior to this.removed
- If the Previous button should be removed [default: true]public void setNextButtonRemoved(boolean removed)
setNextButtonEnabled(boolean)
setDefaultControlsEnabled(boolean)
must be called prior to this.removed
- If the Next button should be removed [default: true]public void setRewindButtonRemoved(boolean removed)
setRewindButtonEnabled(boolean)
setDefaultControlsEnabled(boolean)
must be called prior to this.removed
- If the Rewind button should be removed [default: false]public void setFastForwardButtonRemoved(boolean removed)
setFastForwardButtonEnabled(boolean)
setDefaultControlsEnabled(boolean)
must be called prior to this.removed
- If the Fast Forward button should be removed [default: false]public void setVideoURI(Uri uri)
setVideoURI(Uri, MediaUtil.MediaType)
uri
- The video's Uripublic void setVideoURI(Uri uri, MediaUtil.MediaType defaultMediaType)
uri
- The video's UridefaultMediaType
- The MediaType to use when auto-detection failspublic void setVideoPath(java.lang.String path)
path
- The path to the videopublic Uri getVideoUri()
#setVideoURI(android.net.Uri)
or setVideoPath(String)
then null will be returned.public boolean setVolume(float volume)
volume
- The volume range [0.0 - 1.0]public void reset()
public void seekTo(int milliSeconds)
milliSeconds
- The time to move the playback topublic boolean isPlaying()
public void start()
#setVideoURI(android.net.Uri)
or setVideoPath(String)
. This should be called after the VideoView is correctly
prepared (see #setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)
)public void pause()
startProgressPoll(EMEventBus)
)public void stopPlayback()
startProgressPoll()
)public void suspend()
startProgressPoll()
)public long getDuration()
#setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)
).
If overrideDuration(int)
is set then that value will be returned.public void overrideDuration(int duration)
duration
- The duration for the current media item or < 0 to disablepublic long getCurrentPosition()
#setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)
)public void setPositionOffset(int offset)
getCurrentPosition()
.
This value will be reset when a new audio item is selected.offset
- The millisecond value to offset the positionpublic void restartOverridePosition()
overridePosition(boolean)
).
This will be the value specified with setPositionOffset(int)
or 0 if it hasn't been set.public void overridePosition(boolean override)
override
- True if the position should be overriddenpublic int getBufferPercentage()
#setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)
)public void addExoPlayerListener(ExoPlayerListener listener)
listener
- The listenerpublic void removeExoPlayerListener(ExoPlayerListener listener)
listener
- The listener to removepublic void setOnPreparedListener(MediaPlayer.OnPreparedListener listener)
EMMediaPreparedEvent
listener
- The listenerpublic void setOnCompletionListener(MediaPlayer.OnCompletionListener listener)
EMMediaCompletionEvent
listener
- The listenerpublic void setOnErrorListener(MediaPlayer.OnErrorListener listener)
EMMediaErrorEvent
listener
- The listenerpublic void setOnInfoListener(MediaPlayer.OnInfoListener listener)
listener
- The listener