public final class BDCloudMediaPlayer extends AbstractMediaPlayer
IMediaPlayer.OnBufferingUpdateListener, IMediaPlayer.OnCompletionListener, IMediaPlayer.OnErrorListener, IMediaPlayer.OnInfoListener, IMediaPlayer.OnMetadataListener, IMediaPlayer.OnPreparedListener, IMediaPlayer.OnSeekCompleteListener, IMediaPlayer.OnTimedTextListener, IMediaPlayer.OnVideoSizeChangedListener
限定符和类型 | 字段和说明 |
---|---|
static int |
DECODE_AUTO
默认:优先硬解,无法硬解时软解
|
static int |
DECODE_SW
设置为软解
|
MEDIA_ERROR_IO, MEDIA_ERROR_MALFORMED, MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK, MEDIA_ERROR_SERVER_DIED, MEDIA_ERROR_TIMED_OUT, MEDIA_ERROR_UNKNOWN, MEDIA_ERROR_UNSUPPORTED, MEDIA_INFO_AUDIO_RENDERING_START, MEDIA_INFO_BAD_INTERLEAVING, MEDIA_INFO_BUFFERING_END, MEDIA_INFO_BUFFERING_START, MEDIA_INFO_FRAMECHASING_END, MEDIA_INFO_FRAMECHASING_START, MEDIA_INFO_METADATA_UPDATE, MEDIA_INFO_NETWORK_BANDWIDTH, MEDIA_INFO_NOT_SEEKABLE, MEDIA_INFO_STARTED_AS_NEXT, MEDIA_INFO_SUBTITLE_TIMED_OUT, MEDIA_INFO_TIMED_TEXT_ERROR, MEDIA_INFO_UNKNOWN, MEDIA_INFO_UNSUPPORTED_SUBTITLE, MEDIA_INFO_VIDEO_RENDERING_START, MEDIA_INFO_VIDEO_ROTATION_CHANGED, MEDIA_INFO_VIDEO_TRACK_LAGGING
构造器和说明 |
---|
BDCloudMediaPlayer(android.content.Context context)
默认构造方法
当使用完BDCloudMediaPlayer之后,务必调用
release() 以释放资源,否则过多的BDCloudMediaPlayer实例可能导致异常。 |
BDCloudMediaPlayer(android.content.Context context,
BDCloudLibLoader libLoader)
构造方法
当使用完BDCloudMediaPlayer之后,务必调用
release() 以释放资源,否则过多的BDCloudMediaPlayer实例可能导致异常。 |
限定符和类型 | 方法和说明 |
---|---|
void |
deselectTrack(int track) |
long |
getAsyncStatisticBufBackwards() |
long |
getAsyncStatisticBufCapacity() |
long |
getAsyncStatisticBufForwards() |
long |
getAudioCachedBytes()
获取音频已缓冲好的字节数
|
long |
getAudioCachedDuration()
获取音频已缓冲好的长度
|
long |
getAudioCachedPackets()
获取音频已缓冲好的包数
|
int |
getAudioSessionId() |
long |
getBitRate() |
long |
getCacheStatisticBufForwards() |
long |
getCacheStatisticCountBytes() |
long |
getCacheStatisticFilePos() |
long |
getCacheStatisticPhysicalPos() |
static java.lang.String |
getColorFormatName(int mediaCodecColorFormat) |
long |
getCurrentPosition()
获取当前播放位置,单位为毫秒
|
int |
getCurrentVariantIndex()
获得当前多码率视频的index
|
java.lang.String |
getDataSource()
获取播放路径
|
int |
getDecodeMode()
获取之前设置的解码模式
|
long |
getDownloadSpeed()
获取网络下载速度
|
long |
getDuration()
获取音视频时长,单位为毫秒
|
MediaInfo |
getMediaInfo()
获取媒体信息
包含解码信息与音视频流信息
|
android.os.Bundle |
getMediaMeta() |
static java.lang.String |
getSdkVersion()
获取sdk版本,形式为 xx.xx.xx
|
long |
getSeekLoadDuration() |
int |
getSelectedTrack(int trackType) |
float |
getSpeed(float speed)
获取播放速度,目前仅支持Android 6.0及以上版本
|
BDCloudTrackInfo[] |
getTrackInfo()
获取音视频track的信息
|
long |
getTrafficStatisticByteCount() |
java.lang.String[] |
getVariantInfo()
获得多码率视频的各码率信息
|
long |
getVideoCachedBytes()
获取视频已缓冲好的字节数
|
long |
getVideoCachedDuration()
获取视频已缓冲好的长度
|
long |
getVideoCachedPackets()
获取视频已缓冲好的包数
|
float |
getVideoDecodeFramesPerSecond()
获取视频解码帧率
|
int |
getVideoDecoder()
获取当前视频的decoder类型,1为软解;2为硬解
|
int |
getVideoHeight()
获取视频高度
|
float |
getVideoOutputFramesPerSecond()
获取视频输出帧率
|
int |
getVideoSarDen()
获取采样纵横比的分母
|
int |
getVideoSarNum()
获取采样纵横比的分子
|
int |
getVideoWidth()
获取视频宽度
|
boolean |
isLooping()
是否循环播放
|
boolean |
isPlayable()
是否可播放,当前始终为true
|
boolean |
isPlaying()
是否正在播放
|
static void |
loadLibrariesOnce(BDCloudLibLoader libLoader)
so库定制加载,一般不需要调用。
|
void |
pause()
暂停播放
|
void |
prepareAsync()
异步准备,播放器仅支持异步准备。
|
void |
release()
释放资源
Releases resources associated with this BDCloudMediaPlayer object.
|
void |
reset()
重置,将状态重置为IDLE
重置后需重新设置播放源
|
void |
resetListeners() |
void |
seekTo(long msec)
快速切换到某个时间点进行播放
|
boolean |
selectResolutionByIndex(int index)
切换多分辨率
需要首先调用getVariantInfo拿到数组
|
void |
selectTrack(int track) |
void |
selectVariantByIndex(int index)
设置多码率index。
|
static void |
setAK(java.lang.String akOfBDCloud)
设置Access Key
|
void |
setAudioStreamType(int streamtype)
当前该设置不生效
|
void |
setBufferSizeInBytes(int size)
设置 缓冲过程中,起播数据字节长度
|
void |
setBufferTimeInMs(int time)
设置 缓冲过程中,起播数据时长
|
void |
setCustomizedPlayerIdForHLS(java.lang.String id)
DRM加密相关,一般不需设置
|
void |
setCustomizedPlayerKeyForHLS(java.lang.String key)
DRM加密相关,一般不需设置
|
void |
setDataSource(android.content.Context context,
android.net.Uri uri)
设置播放源
|
void |
setDataSource(android.content.Context context,
android.net.Uri uri,
java.util.Map<java.lang.String,java.lang.String> headers)
设置播放源,可设置请求头信息
|
void |
setDataSource(java.io.FileDescriptor fd)
设置播放源 (FileDescriptor).
|
void |
setDataSource(IMediaDataSource mediaDataSource) |
void |
setDataSource(java.lang.String path)
设置播放源 (file-path or http/rtsp URL)
|
void |
setDataSource(java.lang.String path,
java.util.Map<java.lang.String,java.lang.String> headers)
设置播放源 (file-path or http/rtsp URL),可设置网络请求头部信息。
|
void |
setDecodeMode(int mode)
设置软硬解模式,默认为auto模式(自动检测,优先硬解)
|
void |
setDecryptTokenForHLS(java.lang.String token)
DRM加密-token加密,通过该接口设置token
|
void |
setDisplay(android.view.SurfaceHolder sh)
设置
SurfaceHolder 用于显示视频
如果想显示视频,需要设置SurfaceHolder或者Surface。 |
void |
setInitPlayPosition(long positionInMilliSeconds)
设置初始播放位置, 需在prepareAsync之前调用
|
void |
setKeepInBackground(boolean keepInBackground)
当前该设置不生效
|
static void |
setLocalCacheEnabled(boolean isEnable,
java.lang.String cachePath)
设置是否开启本地缓存功能,开启该功能后,可以在观看过程中将音视频数据临时缓存到本地目录
|
void |
setLogEnabled(boolean enable)
是否显示debug消息
|
void |
setLooping(boolean looping)
设置是否循环播放
|
void |
setMaxCacheSizeInBytes(int size)
设置 最大缓冲区长度
|
void |
setMaxProbeSize(int maxProbeSize)
设置probe(音视频格式探测)最大数据大小
|
void |
setMaxProbeTime(int maxProbeTime)
设置probe(音视频格式探测)最大时长,单位是毫秒
|
void |
setOption(int category,
java.lang.String name,
long value)
设置额外信息,一般不需设置
|
void |
setOption(int category,
java.lang.String name,
java.lang.String value)
设置额外信息,一般不需设置
|
static void |
setP2PEnabled(boolean isEnable)
设置是否开启P2P下载模块
|
void |
setScreenOnWhilePlaying(boolean screenOn)
设置播放时屏幕保持,仅在设置过SurfaceHolder时有效。
|
void |
setSpeed(float speed)
设置播放速度,目前仅支持Android 6.0及以上版本
|
void |
setSurface(android.view.Surface surface)
|
void |
setTimeoutInUs(int timeout)
Setting timeout threshold of network connecting and reading process
|
void |
setVolume(float leftVolume,
float rightVolume)
设置左右声道的音量
|
void |
setWakeMode(android.content.Context context,
int mode)
设置保持唤醒模式
|
void |
start()
启动播放
要求播放源已经准备好
|
void |
stop()
停止播放
|
void |
toggleFrameChasing(boolean isEnable)
设置是否开启追帧播放功能
|
public static final int DECODE_AUTO
public BDCloudMediaPlayer(android.content.Context context)
当使用完BDCloudMediaPlayer之后,务必调用release()
以释放资源,否则过多的BDCloudMediaPlayer实例可能导致异常。
public BDCloudMediaPlayer(android.content.Context context, BDCloudLibLoader libLoader)
当使用完BDCloudMediaPlayer之后,务必调用release()
以释放资源,否则过多的BDCloudMediaPlayer实例可能导致异常。
context
- 上下文libLoader
- 定制so加载器public static void setAK(java.lang.String akOfBDCloud)
akOfBDCloud
- 百度云后台的ak,详见 百度云后台 --> 右上角的用户名 --> "安全认证" --> "Access Key"public static void setP2PEnabled(boolean isEnable)
isEnable
- 是否开启public static void setLocalCacheEnabled(boolean isEnable, java.lang.String cachePath)
isEnable
- 是否开启cachePath
- 临时缓存路径,如果开启本地缓存功能,该路径不能为空public static void loadLibrariesOnce(BDCloudLibLoader libLoader)
libLoader
- public void setDisplay(android.view.SurfaceHolder sh)
SurfaceHolder
用于显示视频
如果想显示视频,需要设置SurfaceHolder或者Surface。既不设置该方法也不设置setSurface(Surface)
方法,会导致仅有音频播放。将
SurfaceHolder或者Surface设置为空,也会导致仅播放音频。
sh
- the SurfaceHolder to use for video displaypublic void setSurface(android.view.Surface surface)
Surface
来显示视频,与接口setDisplay(SurfaceHolder)
功能类似,但不支持setScreenOnWhilePlaying(boolean)
接口的设置。当调用该接口时,之前设置的Surface或SurfaceHolder将被替换。设置为null会仅播放音频。
如果设置的Surface会往SurfaceTexture
发送frames,SurfaceTexture.getTimestamp()
接口返回的时间戳会有未指定的零点。这些时间戳
在不同媒体资源、同一资源的不同实例、同一程序的多次运行的情况中不具有可比性。这个时间戳会单调递增,并且不受时间调整的影响,但在位置设置后会被重置。
surface
- The Surface
to be used for the video portion of the media.public void setDataSource(android.content.Context context, android.net.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 playjava.lang.IllegalStateException
- if it is called in an invalid statejava.io.IOException
java.lang.IllegalArgumentException
java.lang.SecurityException
public void setDataSource(android.content.Context context, android.net.Uri uri, java.util.Map<java.lang.String,java.lang.String> headers) 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 playheaders
- the headers to be sent together with the request for the data Note that the cross domain
redirection is allowed by default, but that can be changed with key/value pairs through the headers
parameter with "android-allow-cross-domain-redirect" as the key and "0" or "1" as the value to
disallow or allow cross domain redirection.java.lang.IllegalStateException
- if it is called in an invalid statejava.io.IOException
java.lang.IllegalArgumentException
java.lang.SecurityException
public void setDataSource(java.lang.String path) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.SecurityException, java.lang.IllegalStateException
path
- the path of the file, or the http/rtsp URL of the stream you want to playjava.lang.IllegalStateException
- if it is called in an invalid state
When path
refers to a local file, the file may actually be opened by a process other
than the calling application. This implies that the pathname should be an absolute path (as any other
process runs with unspecified current working directory), and that the pathname should reference a
world-readable file.
java.io.IOException
java.lang.IllegalArgumentException
java.lang.SecurityException
public void setDataSource(java.lang.String path, java.util.Map<java.lang.String,java.lang.String> headers) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.SecurityException, java.lang.IllegalStateException
path
- the path of the file, or the http/rtsp URL of the stream you want to playheaders
- the headers associated with the http request for the stream you want to playjava.lang.IllegalStateException
- if it is called in an invalid statejava.io.IOException
java.lang.IllegalArgumentException
java.lang.SecurityException
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 playjava.lang.IllegalStateException
- if it is called in an invalid statejava.io.IOException
java.lang.IllegalArgumentException
public void setDataSource(IMediaDataSource mediaDataSource) throws java.lang.IllegalArgumentException, java.lang.SecurityException, java.lang.IllegalStateException
setDataSource
在接口中 IMediaPlayer
setDataSource
在类中 AbstractMediaPlayer
java.lang.IllegalArgumentException
java.lang.SecurityException
java.lang.IllegalStateException
public java.lang.String getDataSource()
public void prepareAsync() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public void start() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public void stop() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public void pause() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public void setWakeMode(android.content.Context context, int mode)
context
- mode
- 该模式为PowerManager.newWakeLock的接口参数public void setScreenOnWhilePlaying(boolean screenOn)
screenOn
- public BDCloudTrackInfo[] getTrackInfo()
public int getSelectedTrack(int trackType)
public void selectTrack(int track)
public void deselectTrack(int track)
public int getVideoWidth()
public int getVideoHeight()
public int getVideoSarNum()
public int getVideoSarDen()
public boolean isPlaying()
public void seekTo(long msec) throws java.lang.IllegalStateException
msec
- java.lang.IllegalStateException
public long getCurrentPosition()
public long getDuration()
public void release()
public void reset()
public void setLooping(boolean looping)
looping
- whether to loop or notpublic boolean isLooping()
public void setSpeed(float speed)
speed
- public float getSpeed(float speed)
speed
- public int getVideoDecoder()
public float getVideoOutputFramesPerSecond()
public float getVideoDecodeFramesPerSecond()
public long getVideoCachedDuration()
public long getAudioCachedDuration()
public long getVideoCachedBytes()
public long getAudioCachedBytes()
public long getVideoCachedPackets()
public long getAudioCachedPackets()
public long getAsyncStatisticBufBackwards()
public long getAsyncStatisticBufForwards()
public long getAsyncStatisticBufCapacity()
public long getTrafficStatisticByteCount()
public long getCacheStatisticPhysicalPos()
public long getCacheStatisticBufForwards()
public long getCacheStatisticFilePos()
public long getCacheStatisticCountBytes()
public long getBitRate()
public long getDownloadSpeed()
public long getSeekLoadDuration()
public void setVolume(float leftVolume, float rightVolume)
leftVolume
- rightVolume
- public int getAudioSessionId()
public static java.lang.String getSdkVersion()
public MediaInfo getMediaInfo()
public boolean selectResolutionByIndex(int index)
index
- VariantInfo数组的下标。public void setInitPlayPosition(long positionInMilliSeconds)
positionInMilliSeconds
- public void setDecodeMode(int mode)
mode
- 取值为DECODE_AUTO或DECODE_SWpublic int getDecodeMode()
public int getCurrentVariantIndex()
public void selectVariantByIndex(int index)
index
- public void setCustomizedPlayerIdForHLS(java.lang.String id)
id
- public void setCustomizedPlayerKeyForHLS(java.lang.String key)
key
- public void setDecryptTokenForHLS(java.lang.String token)
token
- public void setMaxCacheSizeInBytes(int size)
size
- public void setBufferTimeInMs(int time)
time
- public void setBufferSizeInBytes(int size)
size
- public void setMaxProbeTime(int maxProbeTime)
maxProbeTime
- public void setMaxProbeSize(int maxProbeSize)
maxProbeSize
- public void setTimeoutInUs(int timeout)
timeout
- timeout in uspublic void toggleFrameChasing(boolean isEnable)
isEnable
- 是否开启public java.lang.String[] getVariantInfo()
public void setLogEnabled(boolean enable)
enable
- 当为false时,将仅显示warn级别及以上的消息;public boolean isPlayable()
public void setOption(int category, java.lang.String name, java.lang.String value)
category
- name
- value
- public void setOption(int category, java.lang.String name, long value)
category
- name
- value
- public android.os.Bundle getMediaMeta()
public static java.lang.String getColorFormatName(int mediaCodecColorFormat)
public void setAudioStreamType(int streamtype)
streamtype
- public void setKeepInBackground(boolean keepInBackground)
keepInBackground
- public void resetListeners()
resetListeners
在类中 AbstractMediaPlayer