|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object io.vov.vitamio.MediaPlayer
public class MediaPlayer
MediaPlayer class can be used to control playback of audio/video files and
streams. An example on how to use the methods in this class can be found in
VideoView
. This class will function the same as
android.media.MediaPlayer in most cases. Please see Audio and
Video for additional help using MediaPlayer.
Nested Class Summary | |
---|---|
static interface |
MediaPlayer.OnBufferingUpdateListener
|
static interface |
MediaPlayer.OnCompletionListener
|
static interface |
MediaPlayer.OnErrorListener
|
static interface |
MediaPlayer.OnInfoListener
|
static interface |
MediaPlayer.OnPreparedListener
|
static interface |
MediaPlayer.OnSeekCompleteListener
|
static interface |
MediaPlayer.OnSubtitleUpdateListener
|
static interface |
MediaPlayer.OnVideoSizeChangedListener
|
Field Summary | |
---|---|
static int |
MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK
|
static int |
MEDIA_ERROR_UNKNOWN
|
static int |
MEDIA_INFO_BUFFERING_END
MediaPlayer is resuming playback after filling buffers. |
static int |
MEDIA_INFO_BUFFERING_START
MediaPlayer is temporarily pausing playback internally in order to buffer more data. |
static int |
MEDIA_INFO_NOT_SEEKABLE
The media cannot be seeked (e.g live stream) |
static int |
MEDIA_INFO_VIDEO_TRACK_LAGGING
The video is too complex for the decoder: it can't decode frames fast enough. |
static java.lang.String[] |
SUB_TYPES
The external subtitle types which Vitamio supports. |
static int |
SUBTITLE_EXTERNAL
The subtitle displayed is an external file |
static int |
SUBTITLE_INTERNAL
The subtitle displayed is embeded in the movie |
static int |
VIDEOQUALITY_HIGH
|
static int |
VIDEOQUALITY_LOW
|
static int |
VIDEOQUALITY_MEDIUM
|
Constructor Summary | |
---|---|
MediaPlayer(Context ctx)
Default constructor. |
Method Summary | |
---|---|
int |
getAudioTrack()
Get the audio track number in playback |
java.util.HashMap<java.lang.String,java.lang.Integer> |
getAudioTrackMap(java.lang.String encoding)
Get the audio tracks embeded in the movie (e.g. |
int |
getBufferProgress()
|
long |
getCurrentPosition()
Gets the current playback position. |
long |
getDuration()
Gets the duration of the file. |
java.lang.String |
getMetaEncoding()
Get the encoding if haven't set with setMetaEncoding(String) |
int |
getSubLocation()
|
java.lang.String |
getSubPath()
You can get the file-path of the external subtitle in use. |
int |
getSubTrack()
Get the subtitle track number in playback |
java.util.HashMap<java.lang.String,java.lang.Integer> |
getSubTrackMap(java.lang.String encoding)
Get the subtitles embeded in the movie (e.g. |
float |
getVideoAspectRatio()
Returns the aspect ratio of the video. |
int |
getVideoHeight()
Returns the height of the video. |
int |
getVideoWidth()
Returns the width of the video. |
boolean |
isBuffering()
Checks whether the buffer is filled |
boolean |
isPlaying()
Checks whether the MediaPlayer is playing. |
void |
pause()
Pauses playback. |
void |
prepare()
Prepares the player for playback, synchronously. |
void |
prepareAsync()
Prepares the player for playback, asynchronously. |
void |
release()
Releases resources associated with this MediaPlayer object. |
void |
releaseDisplay()
Calling this result in only the audio track being played. |
void |
reset()
Resets the MediaPlayer to its uninitialized state. |
void |
seekTo(long msec)
Seeks to specified time position. |
void |
setAudioTrack(int audioIndex)
Set the audio track to play, must be in the result of getAudioTrackMap(String) |
void |
setBufferSize(int bufSize)
The buffer to fill before playback, default is 1024KB |
void |
setDataSource(Context context,
Uri uri)
Sets the data source as a content Uri. |
void |
setDataSource(java.io.FileDescriptor fd)
Sets the data source (FileDescriptor) to use. |
void |
setDataSource(java.lang.String path)
Sets the data source (file-path or http/rtsp/mms URL) to use. |
void |
setDisplay(SurfaceHolder sh)
Sets the SurfaceHolder to use for displaying the video portion of the media. |
void |
setMetaEncoding(java.lang.String encoding)
Set the encoding MediaPlayer will use to determine the metadata |
void |
setOnBufferingUpdateListener(MediaPlayer.OnBufferingUpdateListener listener)
Register a callback to be invoked when the status of a network stream's buffer has changed. |
void |
setOnCompletionListener(MediaPlayer.OnCompletionListener listener)
Register a callback to be invoked when the end of a media source has been reached during playback. |
void |
setOnErrorListener(MediaPlayer.OnErrorListener listener)
Register a callback to be invoked when an error has happened during an asynchronous operation. |
void |
setOnInfoListener(MediaPlayer.OnInfoListener listener)
|
void |
setOnPreparedListener(MediaPlayer.OnPreparedListener listener)
Register a callback to be invoked when the media source is ready for playback. |
void |
setOnSeekCompleteListener(MediaPlayer.OnSeekCompleteListener listener)
Register a callback to be invoked when a seek operation has been completed. |
void |
setOnSubtitleUpdateListener(MediaPlayer.OnSubtitleUpdateListener listener)
Register a callback to be invoked when a subtitle need to display. |
void |
setOnVideoSizeChangedListener(MediaPlayer.OnVideoSizeChangedListener listener)
Register a callback to be invoked when the video size is known or updated. |
void |
setScreenOnWhilePlaying(boolean screenOn)
Control whether we should use the attached SurfaceHolder to keep the screen on while video playback is occurring. |
void |
setSubEncoding(java.lang.String encoding)
Set the encoding to display text subtitle. |
void |
setSubPath(java.lang.String subPath)
Set the file-path of an external subtitle. |
void |
setSubShown(boolean shown)
Tell the MediaPlayer whether to show subtitle |
void |
setSubTrack(int trackId)
Set the subtitle track to display, must be in the result of getSubTrackMap(String) |
void |
setVideoQuality(int quality)
Set the quality when play video, if the video is too lag, you may try VIDEOQUALITY_LOW, default is VIDEOQUALITY_LOW. |
void |
setVolume(float leftVolume,
float rightVolume)
|
void |
setWakeMode(Context context,
int mode)
Set the low-level power management behavior for this MediaPlayer. |
void |
start()
Starts or resumes playback. |
void |
stop()
The same as pause() |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MEDIA_ERROR_UNKNOWN
public static final int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK
public static final int MEDIA_INFO_VIDEO_TRACK_LAGGING
MediaPlayer.OnInfoListener
,
Constant Field Valuespublic static final int MEDIA_INFO_BUFFERING_START
public static final int MEDIA_INFO_BUFFERING_END
public static final int MEDIA_INFO_NOT_SEEKABLE
MediaPlayer.OnInfoListener
,
Constant Field Valuespublic static final int VIDEOQUALITY_LOW
public static final int VIDEOQUALITY_MEDIUM
public static final int VIDEOQUALITY_HIGH
public static final int SUBTITLE_INTERNAL
public static final int SUBTITLE_EXTERNAL
public static final java.lang.String[] SUB_TYPES
Constructor Detail |
---|
public MediaPlayer(Context ctx) throws VitamioInstaller.VitamioNotCompatibleException, VitamioInstaller.VitamioNotFoundException
VitamioInstaller.VitamioNotCompatibleException
if
Vitamio not compatible with user's device,
VitamioInstaller.VitamioNotFoundException
if
Vitamio not installed in the device.
When done with the MediaPlayer, you should call release()
, to
free the resources. If not released, too many MediaPlayer instances may
result in an exception.
VitamioInstaller.VitamioNotCompatibleException
VitamioInstaller.VitamioNotFoundException
Method Detail |
---|
public void setDisplay(SurfaceHolder sh)
sh
- the SurfaceHolder to use for video displaypublic void setDataSource(Context context, Uri uri) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.SecurityException, java.lang.IllegalStateException
context
- the Context to use when resolving the Uriuri
- the Content URI of the data you want to play
java.lang.IllegalStateException
- if it is called in an invalid state
java.io.IOException
java.lang.IllegalArgumentException
java.lang.SecurityException
public void setDataSource(java.lang.String path) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException
path
- the path of the file, or the http/rtsp/mms URL of the stream
you want to play
java.lang.IllegalStateException
- if it is called in an invalid state
java.io.IOException
java.lang.IllegalArgumentException
public void setDataSource(java.io.FileDescriptor fd) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException
fd
- the FileDescriptor for the file you want to play
java.lang.IllegalStateException
- if it is called in an invalid state
java.io.IOException
java.lang.IllegalArgumentException
public void prepare() throws java.io.IOException, java.lang.IllegalStateException
java.lang.IllegalStateException
- if it is called in an invalid state
java.io.IOException
public void prepareAsync() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if it is called in an invalid statepublic void start() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if it is called in an invalid statepublic void stop() throws java.lang.IllegalStateException
pause()
java.lang.IllegalStateException
- if the internal player engine has not been
initialized.public void pause() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the internal player engine has not been
initialized.public void setWakeMode(Context context, int mode)
setDisplay(SurfaceHolder)
and thus can use the
high-level setScreenOnWhilePlaying(boolean)
feature.
This function has the MediaPlayer access the low-level power manager
service to control the device's power usage while playing is occurring.
The parameter is a combination of android.os.PowerManager
wake
flags. Use of this method requires
android.Manifest.permission#WAKE_LOCK
permission. By default, no
attempt is made to keep the device awake during playback.
context
- the Context to usemode
- the power/wake mode to setandroid.os.PowerManager
public void setScreenOnWhilePlaying(boolean screenOn)
setWakeMode(Context, int)
where possible, since it doesn't require that
the application have permission for low-level wake lock access.
screenOn
- Supply true to keep the screen on, false to allow it to
turn off.public int getVideoWidth()
setOnVideoSizeChangedListener(OnVideoSizeChangedListener)
to
provide a notification when the width is available.public int getVideoHeight()
setOnVideoSizeChangedListener(OnVideoSizeChangedListener)
to
provide a notification when the height is available.public boolean isPlaying()
public void seekTo(long msec) throws java.lang.IllegalStateException
msec
- the offset in milliseconds from the start to seek to
java.lang.IllegalStateException
- if the internal player engine has not been
initializedpublic long getCurrentPosition()
public long getDuration()
public void release()
public void reset()
public void setVolume(float leftVolume, float rightVolume)
public void setOnPreparedListener(MediaPlayer.OnPreparedListener listener)
listener
- the callback that will be runpublic void setOnCompletionListener(MediaPlayer.OnCompletionListener listener)
listener
- the callback that will be runpublic void setOnBufferingUpdateListener(MediaPlayer.OnBufferingUpdateListener listener)
listener
- the callback that will be run.public void setOnSeekCompleteListener(MediaPlayer.OnSeekCompleteListener listener)
listener
- the callback that will be runpublic void setOnVideoSizeChangedListener(MediaPlayer.OnVideoSizeChangedListener listener)
listener
- the callback that will be runpublic void setOnErrorListener(MediaPlayer.OnErrorListener listener)
listener
- the callback that will be runpublic void setOnInfoListener(MediaPlayer.OnInfoListener listener)
public void setOnSubtitleUpdateListener(MediaPlayer.OnSubtitleUpdateListener listener)
listener
- the callback that will be runpublic void releaseDisplay()
public float getVideoAspectRatio()
io.vov.vitamio.VideoView#setVideoLayout(int, float)
public void setVideoQuality(int quality)
quality
- public void setBufferSize(int bufSize)
bufSize
- buffer size in Bytepublic boolean isBuffering()
public int getBufferProgress()
MediaPlayer.OnBufferingUpdateListener
public void setMetaEncoding(java.lang.String encoding)
encoding
- e.g. "UTF-8"public java.lang.String getMetaEncoding()
setMetaEncoding(String)
public java.util.HashMap<java.lang.String,java.lang.Integer> getAudioTrackMap(java.lang.String encoding)
encoding
- the encoding to format String, will detect it if null
public int getAudioTrack()
public void setAudioTrack(int audioIndex)
getAudioTrackMap(String)
audioIndex
- the track numberpublic void setSubShown(boolean shown)
shown
- true if wanna showpublic void setSubEncoding(java.lang.String encoding)
encoding
- MediaPlayer will detet it if nullpublic int getSubLocation()
public void setSubPath(java.lang.String subPath)
subPath
- must be a local filepublic java.lang.String getSubPath()
public void setSubTrack(int trackId)
getSubTrackMap(String)
audioIndex
- the track numberpublic int getSubTrack()
public java.util.HashMap<java.lang.String,java.lang.Integer> getSubTrackMap(java.lang.String encoding)
encoding
- the encoding to format String, will detect it if null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |