public class CyberPlayer extends java.lang.Object implements CyberPlayerCore.OnCompletionListener, CyberPlayerCore.OnCompletionWithParamListener, CyberPlayerCore.OnPreparedListener, CyberPlayerCore.OnPlayingStatusListener, CyberPlayerCore.OnErrorListener, CyberPlayerCore.OnBufferingUpdateListener, CyberPlayerCore.OnSeekCompleteListener, CyberPlayerCore.OnInfoListener, CyberPlayerCore.OnVideoSizeChangedListener, CyberPlayerCore.OnPlayingBufferCacheListener, CyberPlayerCore.OnNetworkSpeedUpdateListener
Modifier and Type | Class and Description |
---|---|
static interface |
CyberPlayer.OnBufferingUpdateListener
Interface definition of a callback to be invoked indicating buffering
status of a media resource being streamed over the network.
|
static interface |
CyberPlayer.OnCompletionListener
Interface definition for a callback to be invoked when playback of a
media source has completed.
|
static interface |
CyberPlayer.OnCompletionWithParamListener |
static interface |
CyberPlayer.OnErrorListener
Interface definition of a callback to be invoked when there has been an
error during an asynchronous operation (other errors will throw
exceptions at method call time).
|
static interface |
CyberPlayer.OnInfoListener
Interface definition of a callback to be invoked to communicate some info
and/or warning about the media or its playback.
|
static interface |
CyberPlayer.OnOnNetworkSpeedListener |
static interface |
CyberPlayer.OnPlayingBufferCacheListener |
static interface |
CyberPlayer.OnPreparedListener
Interface definition for a callback to be invoked when the media source
is ready for playback.
|
static interface |
CyberPlayer.OnSeekCompleteListener
Interface definition of a callback to be invoked indicating the
completion of a seek operation.
|
static interface |
CyberPlayer.OnVideoSizeChangedListener
Interface definition of a callback to be invoked when the video size is
first known or updated
|
Modifier and Type | Field and Description |
---|---|
static int |
DECODE_HW |
static int |
DECODE_MHW |
static int |
DECODE_MHW_AUTO |
static int |
DECODE_SW |
static int |
MEDIA_ERROR_EIO |
static int |
MEDIA_ERROR_INVALID_INPUTFILE |
static int |
MEDIA_ERROR_MC_EXCEPTION
DECODE_MHW 模式出现异常
|
static int |
MEDIA_ERROR_MC_LOW_SYSTEM_VERSION
DECODE_MHW 不支持,系统版本过低
|
static int |
MEDIA_ERROR_MC_NOT_SUPPORT
DECODE_MHW 不支持当前的视频规格(mime type, profile, level)
|
static int |
MEDIA_ERROR_NO_INPUTFILE |
static int |
MEDIA_ERROR_NO_SUPPORTED_CODEC |
static int |
MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK
The video is streamed and its container is not valid for progressive
playback i.e the video's index (e.g moov atom) is not at the start of the
file.
|
static int |
MEDIA_ERROR_SERVER_DIED
Media server died.
|
static int |
MEDIA_ERROR_SET_VIDEOMODE |
static int |
MEDIA_ERROR_UAS_ERR_USER_SIGN |
static int |
MEDIA_ERROR_UAS_ERRORPARAM |
static int |
MEDIA_ERROR_UAS_USER_NOT_EXIT |
static int |
MEDIA_ERROR_UNKNOWN
Unspecified media player error.
|
static int |
MEDIA_INFO_BAD_INTERLEAVING
Bad interleaving means that a media has been improperly interleaved or
not interleaved at all, e.g has all the video samples first then all the
audio ones.
|
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_METADATA_UPDATE
A new set of metadata is available.
|
static int |
MEDIA_INFO_NOT_SEEKABLE
The media cannot be seeked (e.g live stream)
|
static int |
MEDIA_INFO_PLAYING_AVDIFFERENCE |
static int |
MEDIA_INFO_PLAYING_QUALITY |
static int |
MEDIA_INFO_UNKNOWN
Unspecified media player info.
|
static int |
MEDIA_INFO_VIDEO_TRACK_LAGGING
The video is too complex for the decoder: it can't decode frames fast
enough.
|
static int |
VIDEO_SCALING_MODE_SCALE_TO_FIT |
static int |
VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING |
Constructor and Description |
---|
CyberPlayer(Context context)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
getCurrentDecodeMode()
get current decode mode
|
java.lang.String |
getCurrentPlayingUrl() |
double |
getCurrentPositionInMsecs()
Gets the current playback position.
|
double |
getDuration()
Gets the duration of the file.
|
double |
getDuration(int mode) |
int[] |
getSupportedBitrateKb() |
java.lang.String[] |
getSupportedResolutionKb() |
java.lang.String |
getVersion() |
int |
getVideoHeight()
Returns the height of the video.
|
int |
getVideoWidth()
Returns the width of the video.
|
boolean |
isPlaying()
Checks whether the MediaPlayer is playing.
|
void |
manualSyncSubtitle(int mSec) |
void |
onBufferingUpdate(com.baidu.cyberplayer.core.CyberPlayerCore mp,
int percent)
Called to update status in buffering a media stream.
|
void |
onBufferingUpdate(MediaPlayer arg0,
int arg1)
Called to update status in buffering a media stream.
|
void |
onCompletion(com.baidu.cyberplayer.core.CyberPlayerCore mp)
Called when the end of a media source is reached during playback.
|
void |
onCompletion(MediaPlayer arg0)
Called when the end of a media source is reached during playback.
|
void |
onCompletionWithParam(com.baidu.cyberplayer.core.CyberPlayerCore mp,
int param)
Called when the end of a media source is reached during playback.
|
boolean |
onError(com.baidu.cyberplayer.core.CyberPlayerCore mp,
int what,
int extra)
Called to indicate an error.
|
boolean |
onError(MediaPlayer arg0,
int arg1,
int arg2)
Called to indicate an error.
|
boolean |
onInfo(com.baidu.cyberplayer.core.CyberPlayerCore mp,
int what,
int extra)
Called to indicate an info or a warning.
|
boolean |
onInfo(MediaPlayer arg0,
int arg1,
int arg2)
Called to indicate an info or a warning.
|
void |
onNetworkSpeedUpdate(com.baidu.cyberplayer.core.CyberPlayerCore mp,
int speed)
Called to update status in buffering a media stream.
|
void |
onPlayingBufferCache(com.baidu.cyberplayer.core.CyberPlayerCore mp,
int percent) |
void |
onPrepared(com.baidu.cyberplayer.core.CyberPlayerCore mp)
Called when the media file is ready for playback.
|
void |
onPrepared(MediaPlayer arg0)
Called when the media file is ready for playback.
|
void |
onSeekComplete(com.baidu.cyberplayer.core.CyberPlayerCore mp)
Called to indicate the completion of a seek operation.
|
void |
onSeekComplete(MediaPlayer arg0)
Called to indicate the completion of a seek operation.
|
void |
onStatusChanged(com.baidu.cyberplayer.core.CyberPlayerCore mp,
int isPlaying)
Called when the playing status is changed.
|
void |
onVideoSizeChanged(com.baidu.cyberplayer.core.CyberPlayerCore mp,
int width,
int height)
Called to indicate the video size
|
void |
onVideoSizeChanged(MediaPlayer arg0,
int arg1,
int arg2)
Called to indicate the video size
|
int |
openExtSubFile(java.lang.String subFilePath) |
void |
pause()
Pauses playback.
|
void |
prepareAsync()
Prepares the player for playback, asynchronously.
|
void |
release()
Releases resources associated with this MediaPlayer object.
|
void |
reset()
Resets the MediaPlayer to its uninitialized state.
|
void |
seekTo(double msec)
Seeks to specified time position.
|
void |
selectResolutionType(int resIndex) |
void |
setAutoVideoCloudTranscoding(boolean enableCVT) |
static void |
setBAEKey(java.lang.String accessKey,
java.lang.String secretKey) |
static void |
setCacheTime(float timeSec) |
static void |
setCustomHttpHeader(java.lang.String httpHeaderBuffer) |
void |
setDataSource(java.lang.String path)
Sets the data source (file-path or http/rtsp URL) to use.
|
boolean |
setDecodeMode(int mode)
you must call setDecodeMode before calling setDisplay() and
prepare()/prepareAsync()
|
void |
setDisplay(CyberPlayerSurface sv)
Sets the SurfaceHolder to use for displaying the video portion of the
media.
|
static void |
setEnableDolby(boolean bEnableDolby) |
static void |
setEnableP2p(boolean bEnableP2p) |
static void |
setExtSubtitleFile(java.lang.String extSubtitleFile) |
static void |
setLogLevel(int level) |
static void |
setNativeBufferSize(long size) |
static void |
setNativeFilesDirectory(java.lang.String nativeFilesDir) |
static void |
setNativeLibsFileName(java.lang.String playerName,
java.lang.String ffmpegName) |
static void |
setNativeLlibsDirectory(java.lang.String nativeLibsDir) |
void |
setOnBufferingUpdateListener(CyberPlayer.OnBufferingUpdateListener listener)
Register a callback to be invoked when the status of a network stream's
buffer has changed.
|
void |
setOnCompletionListener(CyberPlayer.OnCompletionListener listener)
Register a callback to be invoked when the end of a media source has been
reached during playback.
|
void |
setOnCompletionWithParamListener(CyberPlayer.OnCompletionWithParamListener listener) |
void |
setOnErrorListener(CyberPlayer.OnErrorListener listener)
Register a callback to be invoked when an error has happened during an
asynchronous operation.
|
void |
setOnInfoListener(CyberPlayer.OnInfoListener listener)
Register a callback to be invoked when an info/warning is available.
|
void |
setOnNetworkSpeedListener(CyberPlayer.OnOnNetworkSpeedListener listener) |
void |
setOnPlayingBufferCacheListener(CyberPlayer.OnPlayingBufferCacheListener listener) |
void |
setOnPreparedListener(CyberPlayer.OnPreparedListener listener)
Register a callback to be invoked when the media source is ready for
playback.
|
void |
setOnSeekCompleteListener(CyberPlayer.OnSeekCompleteListener listener)
Register a callback to be invoked when a seek operation has been
completed.
|
void |
setOnVideoSizeChangedListener(CyberPlayer.OnVideoSizeChangedListener listener)
Register a callback to be invoked when the video size is known or
updated.
|
static void |
setP2pCachePath(java.lang.String strP2pCachePath) |
static void |
setParametKey(java.lang.String strKey,
java.lang.String value) |
static void |
setRetainLastFrame(boolean enable) |
void |
setSubtitleAlignMethod(int iAlignMethod) |
void |
setSubtitleColor(int iColor) |
void |
setSubtitleFontScale(int iFontScale) |
void |
setSubtitleVisibility(int isShow) |
static void |
setUserAgent(java.lang.String ua) |
void |
setVideoCloudTransLevel(int transcodeLevel) |
void |
setVideoScalingMode(int mode) |
void |
start()
Starts or resumes playback.
|
void |
stop()
Stops playback after playback has been stopped or paused.
|
void |
surfaceChanged(SurfaceHolder holder,
int format,
int width,
int height) |
void |
surfaceCreated(SurfaceHolder holder) |
void |
surfaceDestroyed(SurfaceHolder holder) |
Bitmap |
takeSnapshot()
Returns the bitmap object of the current video's snapshot.
|
public static final int DECODE_HW
public static final int DECODE_SW
public static final int DECODE_MHW
public static final int DECODE_MHW_AUTO
public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT
public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING
public static final int MEDIA_ERROR_UNKNOWN
android.media.MediaPlayer.OnErrorListener
,
Constant Field Valuespublic static final int MEDIA_ERROR_SERVER_DIED
android.media.MediaPlayer.OnErrorListener
,
Constant Field Valuespublic static final int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK
android.media.MediaPlayer.OnErrorListener
,
Constant Field Valuespublic static final int MEDIA_ERROR_NO_INPUTFILE
public static final int MEDIA_ERROR_INVALID_INPUTFILE
public static final int MEDIA_ERROR_NO_SUPPORTED_CODEC
public static final int MEDIA_ERROR_SET_VIDEOMODE
public static final int MEDIA_ERROR_EIO
public static final int MEDIA_ERROR_UAS_ERRORPARAM
public static final int MEDIA_ERROR_UAS_USER_NOT_EXIT
public static final int MEDIA_ERROR_UAS_ERR_USER_SIGN
public static final int MEDIA_ERROR_MC_EXCEPTION
public static final int MEDIA_ERROR_MC_LOW_SYSTEM_VERSION
public static final int MEDIA_ERROR_MC_NOT_SUPPORT
public static final int MEDIA_INFO_UNKNOWN
android.media.MediaPlayer.OnInfoListener
,
Constant Field Valuespublic static final int MEDIA_INFO_VIDEO_TRACK_LAGGING
android.media.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_BAD_INTERLEAVING
android.media.MediaPlayer.OnInfoListener
,
Constant Field Valuespublic static final int MEDIA_INFO_NOT_SEEKABLE
android.media.MediaPlayer.OnInfoListener
,
Constant Field Valuespublic static final int MEDIA_INFO_METADATA_UPDATE
android.media.MediaPlayer.OnInfoListener
,
Constant Field Valuespublic static final int MEDIA_INFO_PLAYING_QUALITY
public static final int MEDIA_INFO_PLAYING_AVDIFFERENCE
public CyberPlayer(Context context)
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.
public static void setLogLevel(int level)
level
- 0: no log output 1: Error 2: Error/Waring 3: Error/Waring/Info
4: Error/Waring/Info/DEBUG 5: Error/Waring/Info/DEBUG/VERBOSE
other: invalid valuepublic static void setNativeBufferSize(long size)
size
- (byte) buffer size only for software decode default size is 5
* 1024 * 1024public static void setCacheTime(float timeSec)
timeSec
- caching timepublic static void setUserAgent(java.lang.String ua)
public static void setParametKey(java.lang.String strKey, java.lang.String value)
public static void setCustomHttpHeader(java.lang.String httpHeaderBuffer)
public static void setP2pCachePath(java.lang.String strP2pCachePath)
public static void setEnableP2p(boolean bEnableP2p)
public static void setEnableDolby(boolean bEnableDolby)
public static void setRetainLastFrame(boolean enable)
public static void setBAEKey(java.lang.String accessKey, java.lang.String secretKey)
public static void setExtSubtitleFile(java.lang.String extSubtitleFile)
public static void setNativeLlibsDirectory(java.lang.String nativeLibsDir)
public static void setNativeFilesDirectory(java.lang.String nativeFilesDir)
public static void setNativeLibsFileName(java.lang.String playerName, java.lang.String ffmpegName)
public void setVideoScalingMode(int mode)
public void setAutoVideoCloudTranscoding(boolean enableCVT)
public void setVideoCloudTransLevel(int transcodeLevel)
public void setDisplay(CyberPlayerSurface sv)
sh
- the SurfaceHolder to use for video displaypublic int getCurrentDecodeMode()
public java.lang.String getVersion()
public boolean setDecodeMode(int mode)
mode
- public void setDataSource(java.lang.String path) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.io.IOException
path
- the path of the file, or the http/rtsp URL of the stream you
want to playjava.io.IOException
java.lang.IllegalArgumentException
java.lang.IllegalStateException
- if it is called in an invalid statepublic 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
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 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 void setSubtitleVisibility(int isShow)
public void setSubtitleColor(int iColor)
public void setSubtitleFontScale(int iFontScale)
public void setSubtitleAlignMethod(int iAlignMethod)
public void manualSyncSubtitle(int mSec)
public Bitmap takeSnapshot()
null.
- public int openExtSubFile(java.lang.String subFilePath)
public boolean isPlaying()
public void seekTo(double msec) throws java.lang.IllegalStateException
msec
- the offset in milliseconds from the start to seek tojava.lang.IllegalStateException
- if the internal player engine has not been initializedpublic void selectResolutionType(int resIndex)
public double getCurrentPositionInMsecs()
public java.lang.String getCurrentPlayingUrl()
public double getDuration()
public double getDuration(int mode)
public void release()
public void reset()
public void setOnPreparedListener(CyberPlayer.OnPreparedListener listener)
listener
- the callback that will be runpublic void setOnCompletionListener(CyberPlayer.OnCompletionListener listener)
listener
- the callback that will be runpublic void setOnCompletionWithParamListener(CyberPlayer.OnCompletionWithParamListener listener)
public void setOnBufferingUpdateListener(CyberPlayer.OnBufferingUpdateListener listener)
listener
- the callback that will be run.public void setOnPlayingBufferCacheListener(CyberPlayer.OnPlayingBufferCacheListener listener)
public void setOnNetworkSpeedListener(CyberPlayer.OnOnNetworkSpeedListener listener)
public void setOnSeekCompleteListener(CyberPlayer.OnSeekCompleteListener listener)
listener
- the callback that will be runpublic void setOnVideoSizeChangedListener(CyberPlayer.OnVideoSizeChangedListener listener)
listener
- the callback that will be runpublic void setOnErrorListener(CyberPlayer.OnErrorListener listener)
listener
- the callback that will be runpublic void setOnInfoListener(CyberPlayer.OnInfoListener listener)
listener
- the callback that will be runpublic void onSeekComplete(com.baidu.cyberplayer.core.CyberPlayerCore mp)
CyberPlayerCore.OnSeekCompleteListener
onSeekComplete
in interface CyberPlayerCore.OnSeekCompleteListener
mp
- the MediaPlayer that issued the seek operationpublic void onBufferingUpdate(com.baidu.cyberplayer.core.CyberPlayerCore mp, int percent)
CyberPlayerCore.OnBufferingUpdateListener
onBufferingUpdate
in interface CyberPlayerCore.OnBufferingUpdateListener
mp
- the MediaPlayer the update pertains topercent
- the percentage (0-100) of the buffer
that has been filled thus farpublic boolean onError(com.baidu.cyberplayer.core.CyberPlayerCore mp, int what, int extra)
CyberPlayerCore.OnErrorListener
onError
in interface CyberPlayerCore.OnErrorListener
mp
- the MediaPlayer the error pertains towhat
- the type of error that has occurred:
extra
- an extra code, specific to the error. Typically
implementation dependant.public void onPrepared(com.baidu.cyberplayer.core.CyberPlayerCore mp)
CyberPlayerCore.OnPreparedListener
onPrepared
in interface CyberPlayerCore.OnPreparedListener
mp
- the MediaPlayer that is ready for playbackpublic void onStatusChanged(com.baidu.cyberplayer.core.CyberPlayerCore mp, int isPlaying)
CyberPlayerCore.OnPlayingStatusListener
onStatusChanged
in interface CyberPlayerCore.OnPlayingStatusListener
mp
- the MediaPlayer's playing status is changed.public void onCompletion(com.baidu.cyberplayer.core.CyberPlayerCore mp)
CyberPlayerCore.OnCompletionListener
onCompletion
in interface CyberPlayerCore.OnCompletionListener
mp
- the MediaPlayer that reached the end of the filepublic void onCompletionWithParam(com.baidu.cyberplayer.core.CyberPlayerCore mp, int param)
CyberPlayerCore.OnCompletionWithParamListener
onCompletionWithParam
in interface CyberPlayerCore.OnCompletionWithParamListener
mp
- the MediaPlayer that reached the end of the filepublic void onVideoSizeChanged(com.baidu.cyberplayer.core.CyberPlayerCore mp, int width, int height)
CyberPlayerCore.OnVideoSizeChangedListener
onVideoSizeChanged
in interface CyberPlayerCore.OnVideoSizeChangedListener
mp
- the MediaPlayer associated with this callbackwidth
- the width of the videoheight
- the height of the videopublic boolean onInfo(com.baidu.cyberplayer.core.CyberPlayerCore mp, int what, int extra)
CyberPlayerCore.OnInfoListener
onInfo
in interface CyberPlayerCore.OnInfoListener
mp
- the MediaPlayer the info pertains to.what
- the type of info or warning.
extra
- an extra code, specific to the info. Typically
implementation dependant.public void onVideoSizeChanged(MediaPlayer arg0, int arg1, int arg2)
CyberPlayerCore.OnVideoSizeChangedListener
onVideoSizeChanged
in interface CyberPlayerCore.OnVideoSizeChangedListener
arg0
- the MediaPlayer associated with this callbackarg1
- the width of the videoarg2
- the height of the videopublic boolean onInfo(MediaPlayer arg0, int arg1, int arg2)
CyberPlayerCore.OnInfoListener
onInfo
in interface CyberPlayerCore.OnInfoListener
arg0
- the MediaPlayer the info pertains to.arg1
- the type of info or warning.
arg2
- an extra code, specific to the info. Typically
implementation dependant.public void onSeekComplete(MediaPlayer arg0)
CyberPlayerCore.OnSeekCompleteListener
onSeekComplete
in interface CyberPlayerCore.OnSeekCompleteListener
arg0
- the MediaPlayer that issued the seek operationpublic void onBufferingUpdate(MediaPlayer arg0, int arg1)
CyberPlayerCore.OnBufferingUpdateListener
onBufferingUpdate
in interface CyberPlayerCore.OnBufferingUpdateListener
arg0
- the MediaPlayer the update pertains toarg1
- the percentage (0-100) of the buffer
that has been filled thus farpublic void onPlayingBufferCache(com.baidu.cyberplayer.core.CyberPlayerCore mp, int percent)
onPlayingBufferCache
in interface CyberPlayerCore.OnPlayingBufferCacheListener
public void onNetworkSpeedUpdate(com.baidu.cyberplayer.core.CyberPlayerCore mp, int speed)
CyberPlayerCore.OnNetworkSpeedUpdateListener
onNetworkSpeedUpdate
in interface CyberPlayerCore.OnNetworkSpeedUpdateListener
mp
- the MediaPlayer the update pertains topublic boolean onError(MediaPlayer arg0, int arg1, int arg2)
CyberPlayerCore.OnErrorListener
onError
in interface CyberPlayerCore.OnErrorListener
arg0
- the MediaPlayer the error pertains toarg1
- the type of error that has occurred:
arg2
- an extra code, specific to the error. Typically
implementation dependant.public void onPrepared(MediaPlayer arg0)
CyberPlayerCore.OnPreparedListener
onPrepared
in interface CyberPlayerCore.OnPreparedListener
arg0
- the MediaPlayer that is ready for playbackpublic void onCompletion(MediaPlayer arg0)
CyberPlayerCore.OnCompletionListener
onCompletion
in interface CyberPlayerCore.OnCompletionListener
arg0
- the MediaPlayer that reached the end of the filepublic void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
public void surfaceCreated(SurfaceHolder holder)
public void surfaceDestroyed(SurfaceHolder holder)
public int[] getSupportedBitrateKb()
public java.lang.String[] getSupportedResolutionKb()