com.ksyun.media.player.KSYMediaPlayer |
播放SDK的核心类,实现播放视频的功能
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
class | KSYMediaPlayer.Builder | 创建KSYMediaPlayer所需的内部类 | |||||||||
enum | KSYMediaPlayer.KSYDecodeMode | 播放器解码类型 | |||||||||
enum | KSYMediaPlayer.KSYDeinterlaceMode | 反交错模式,该功能只在使用点播库时方可生效 | |||||||||
enum | KSYMediaPlayer.KSYReloadMode | Reload模式 | |||||||||
interface | KSYMediaPlayer.OnAudioPCMListener | ||||||||||
interface | KSYMediaPlayer.OnVideoRawDataListener | 原始视频数据的回调监听器 | |||||||||
interface | KSYMediaPlayer.OnVideoTextureListener |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | KSY_LOG_DEBUG | ||||||||||
int | KSY_LOG_DEFAULT | ||||||||||
int | KSY_LOG_ERROR | ||||||||||
int | KSY_LOG_FATAL | ||||||||||
int | KSY_LOG_INFO | ||||||||||
int | KSY_LOG_SILENT | ||||||||||
int | KSY_LOG_UNKNOWN | ||||||||||
int | KSY_LOG_VERBOSE | ||||||||||
int | KSY_LOG_WARN | ||||||||||
int | MEDIA_MESSAGE_INFO | ||||||||||
int | MEDIA_SET_VIDEO_SAR | ||||||||||
int | SDL_FCC_RV16 | 原始视频输出格式为RGB565 | |||||||||
int | SDL_FCC_RV32 | 原始视频输出格式为RGB8888 | |||||||||
int | VIDEO_SCALING_MODE_NOSCALE_TO_FIT | 视频缩放模式,拉伸模式,视频完全填满显示窗口,视频与窗口比例不匹配画面会有变形setVideoScalingMode(int)
|
|||||||||
int | VIDEO_SCALING_MODE_SCALE_TO_FIT | 视频缩放模式,填充模式,在视频宽高比例与手机宽高比例不一致时,播放可能留有黑边,具体接口setVideoScalingMode(int)
|
|||||||||
int | VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING | 视频缩放模式,裁剪模式,具体接口setVideoScalingMode(int)
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void | _onAudioPCMReady(ByteBuffer buffer, long timestamp, int samplerate, int channels, int fmt) | ||||||||||
void |
addTimedTextSource(String path)
设置外挂字幕的路径,播放器会打开并解码外挂字幕
| ||||||||||
void |
addVideoRawBuffer(byte[] rawBuffer)
将缓存buffer交还给播放器
| ||||||||||
int |
bufferEmptyCount()
获取卡顿次数
| ||||||||||
float |
bufferEmptyDuration()
获取卡顿时长,单位为秒
| ||||||||||
void |
deselectTrack(int trackIndex)
根据流索引关闭对应的流, 流索引可通过
getTrackInfo() 获取 | ||||||||||
void | enableFastPlayMode(boolean enable) | ||||||||||
long | getAudioCachedBytes() | ||||||||||
long | getAudioCachedDuration() | ||||||||||
long | getAudioCachedPackets() | ||||||||||
int |
getAudioSessionId()
获取音频Session ID
| ||||||||||
float |
getBufferTimeMax()
获取当前播放器缓存时长的阈值
| ||||||||||
String |
getClientIP()
获取当前使用者的出口IP地址
| ||||||||||
static String | getColorFormatName(int mediaCodecColorFormat) | ||||||||||
long |
getCurrentPosition()
获取当前播放的进度
| ||||||||||
long | getCurrentPts() | ||||||||||
long | getCurrentVideoPts() | ||||||||||
String | getDataSource() | ||||||||||
long |
getDecodedDataSize()
获取已解码的数据量
| ||||||||||
long |
getDownloadDataSize()
获取已下载的数据量
| ||||||||||
long |
getDuration()
获取当前多媒体文件的时长,须在
IMediaPlayer.OnPreparedListener 发起回调了方可有效 | ||||||||||
String |
getLocalDnsIP()
获取本地DNS服务器的IP地址
| ||||||||||
MediaInfo | getMediaInfo() | ||||||||||
Bundle | getMediaMeta() | ||||||||||
Bitmap | getScreenShot() | ||||||||||
int | getSelectedTrack(int trackType) | ||||||||||
String |
getServerAddress()
获取服务器IP
| ||||||||||
float |
getSpeed()
获取当前播放速度,1.0f为正常播放速度
| ||||||||||
KSYQosInfo |
getStreamQosInfo()
获取当前播放器的缓存状态
| ||||||||||
long | getStreamStartTime() | ||||||||||
KSYTrackInfo[] |
getTrackInfo()
获取当前播放的多媒体文件的流信息
须在
prepareAsync() 成功后调用才有意义 | ||||||||||
static String |
getVersion()
获取播放SDK的版本
| ||||||||||
long | getVideoCachedBytes() | ||||||||||
long | getVideoCachedDuration() | ||||||||||
long | getVideoCachedPackets() | ||||||||||
float |
getVideoDecodeFramesPerSecond()
获取当前视频解码帧率
| ||||||||||
int | getVideoDecoder() | ||||||||||
int |
getVideoHeight()
获取视频的高度,须在
IMediaPlayer.OnPreparedListener 发起回调了方可有效 | ||||||||||
float |
getVideoOutputFramesPerSecond()
获取当前视频渲染的帧率
| ||||||||||
int | getVideoSarDen() | ||||||||||
int | getVideoSarNum() | ||||||||||
int |
getVideoWidth()
获取视频的宽度,须在
IMediaPlayer.OnPreparedListener 发起回调了方可有效 | ||||||||||
boolean |
isLooping()
Checks whether the MediaPlayer is looping or non-looping.
| ||||||||||
boolean | isPlayable() | ||||||||||
boolean |
isPlaying()
播放器是否处于播放状态
| ||||||||||
void |
pause()
暂停播放视频
| ||||||||||
void |
prepareAsync()
准备播放多媒体文件,准备成功后
IMediaPlayer.OnPreparedListener 会发出相应回调 | ||||||||||
void |
release()
Releases resources associated with this KSYMediaPlayer object.
| ||||||||||
void |
reload(String path, boolean flushBuffer, KSYMediaPlayer.KSYReloadMode mode)
reload视频
| ||||||||||
void |
reload(String path, boolean flushBuffer)
reload视频,默认使用
KSY_RELOAD_MODE_FAST 模式 | ||||||||||
void |
reset()
重置播放器,软解情况下会清除屏幕内容
| ||||||||||
void | resetListeners() | ||||||||||
void |
seekTo(long msec, boolean accurate)
快进快退
| ||||||||||
void |
seekTo(long msec)
快进快退
| ||||||||||
void |
selectTrack(int trackIndex)
根据流索引开启对应的流, 流索引可通过
getTrackInfo() 获取 | ||||||||||
void |
setBufferSize(int size)
设置播放器缓存数据的最大值,须在
prepareAsync() 之前调用 | ||||||||||
void |
setBufferTimeMax(float timeSecond)
设置播放器缓存数据时长的最大阈值,只对直播有效,须在
prepareAsync() 之前调用。该值较大,则主播和观众之间延迟较大,该值较小,则对网络波动更敏感,容易引发卡顿 | ||||||||||
void |
setDataSource(FileDescriptor fd)
Sets the data source (FileDescriptor) to use.
| ||||||||||
void |
setDataSource(FileDescriptor fd, long offset, long length)
Sets the data source (FileDescriptor) to use.
| ||||||||||
void |
setDataSource(String path)
Sets the data source (file-path or http/rtsp URL) to use.
| ||||||||||
void |
setDataSource(Context context, Uri uri)
Sets the data source as a content Uri.
| ||||||||||
void |
setDataSource(Context context, Uri uri, Map<String, String> headers)
Sets the data source as a content Uri.
| ||||||||||
void | setDataSource(IMediaDataSource mediaDataSource) | ||||||||||
void |
setDecodeMode(KSYMediaPlayer.KSYDecodeMode mode)
设置播放器的解码类型,须在
prepareAsync() 之前调用 | ||||||||||
void |
setDeinterlaceMode(KSYMediaPlayer.KSYDeinterlaceMode mode)
设置反交错的模式,须使用点播库方可生效
| ||||||||||
void |
setDisplay(SurfaceHolder sh)
Sets the
SurfaceHolder to use for displaying the video portion of
the media. | ||||||||||
void | setLogEnabled(boolean enable) | ||||||||||
void |
setLooping(boolean looping)
Sets the player to be looping or non-looping.
| ||||||||||
boolean |
setMirror(boolean mirror)
设置视频镜像显示
| ||||||||||
void | setOnAudioPCMAvailableListener(KSYMediaPlayer.OnAudioPCMListener listener) | ||||||||||
void | setOnControlMessageListener(KSYMediaPlayer.OnControlMessageListener listener) | ||||||||||
void | setOnVideoTextureListener(KSYMediaPlayer.OnVideoTextureListener listener) | ||||||||||
void |
setPlayableRanges(long startTime, long endTime)
由金山云引入, 设置可播放的范围,仅对点播有效
调用此接口时, 需注意:
1.
| ||||||||||
void |
setPlayerMute(int mute)
设置播放器是否禁音
| ||||||||||
boolean |
setRotateDegree(int degree)
设置旋转角度,旋转方向为逆时针
| ||||||||||
void |
setScreenOnWhilePlaying(boolean screenOn)
设置在播放视频时是否保持屏幕常亮
必须在
setDisplay(SurfaceHolder) 之后调用方可生效 | ||||||||||
void |
setSpeed(float speed)
设置播放速度
| ||||||||||
void |
setSurface(Surface surface)
Sets the Surface to be used as the sink for the video portion of
the media.
| ||||||||||
void |
setTimeout(int prepareTimeout, int readTimeout)
设置准备和读数据超时阈值,需在
prepareAsync() 之前调用方可生效 | ||||||||||
void |
setVideoOffset(float horizontal, float vertical)
设置视频的水平和垂直方向的平移量。以手机屏幕中心为原点建立坐标轴,横纵轴坐标各自平行于手机屏幕边缘。归一化处理后,手机屏幕的坐标取值范围为[-1.0, 1.0]
仅在
VIDEO_SCALING_MODE_SCALE_TO_FIT 模式下本接口方可生效 | ||||||||||
void |
setVideoRawDataListener(KSYMediaPlayer.OnVideoRawDataListener listener)
设置获取原始视频数据的监听器
| ||||||||||
void |
setVideoRenderingState(int mode)
设置当前是否由播放器渲染视频内容,与获取视频内容的回调接口
KSYMediaPlayer.OnVideoRawDataListener 相结合使用 | ||||||||||
void |
setVideoScalingMode(int mode)
设置播放器视频缩放模式
| ||||||||||
void |
setVolume(float leftVolume, float rightVolume)
设置当前播放音频,范围为 0.0f -- 1.0f,左右声道的音量建议一致
| ||||||||||
void | setWakeMode(Context context, int mode) | ||||||||||
void |
shouldAutoPlay(boolean state)
必须在
prepareAsync() 之前调用方可生效
在prepare完成后是否自动开播,默认为 | ||||||||||
void |
softReset()
重置播放器,但是不会清除屏幕内容
| ||||||||||
void |
start()
开始播放视频
| ||||||||||
void |
stop()
停止播放视频
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void | finalize() |
原始视频输出格式为RGB565
原始视频输出格式为RGB8888
视频缩放模式,拉伸模式,视频完全填满显示窗口,视频与窗口比例不匹配画面会有变形setVideoScalingMode(int)
视频缩放模式,填充模式,在视频宽高比例与手机宽高比例不一致时,播放可能留有黑边,具体接口setVideoScalingMode(int)
视频缩放模式,裁剪模式,具体接口setVideoScalingMode(int)
设置外挂字幕的路径,播放器会打开并解码外挂字幕
path | 外挂字幕路径 |
---|
将缓存buffer交还给播放器
获取卡顿次数
获取卡顿时长,单位为秒
获取音频Session ID
获取当前播放器缓存时长的阈值
获取当前使用者的出口IP地址
获取当前播放的进度
获取已解码的数据量
获取已下载的数据量
获取当前多媒体文件的时长,须在IMediaPlayer.OnPreparedListener
发起回调了方可有效
获取本地DNS服务器的IP地址
获取服务器IP
获取当前播放速度,1.0f为正常播放速度
获取播放SDK的版本
获取当前视频解码帧率
获取当前视频渲染的帧率
Checks whether the MediaPlayer is looping or non-looping.
播放器是否处于播放状态
暂停播放视频
IllegalStateException |
---|
准备播放多媒体文件,准备成功后IMediaPlayer.OnPreparedListener
会发出相应回调
IllegalStateException |
---|
Releases resources associated with this KSYMediaPlayer object. It is considered good practice to call this method when you're done using the KSYMediaPlayer. In particular, whenever an Activity of an application is paused (its onPause() method is called), or stopped (its onStop() method is called), this method should be invoked to release the KSYMediaPlayer object, unless the application has a special need to keep the object around. In addition to unnecessary resources (such as memory and instances of codecs) being held, failure to call this method immediately if a KSYMediaPlayer object is no longer needed may also lead to continuous battery consumption for mobile devices, and playback failure for other applications if no multiple instances of the same codec are supported on a device. Even if multiple instances of the same codec are supported, some performance degradation may be expected when unnecessary multiple instances are used at the same time.
reload视频
path | 视频地址 |
---|---|
flushBuffer | 是否flush播放器中的旧数据 |
mode | reload模式KSYMediaPlayer.KSYReloadMode |
IllegalStateException |
---|
reload视频,默认使用KSY_RELOAD_MODE_FAST
模式
path | 视频地址 |
---|---|
flushBuffer | 是否flush播放器中的旧数据 |
IllegalStateException |
---|
重置播放器,软解情况下会清除屏幕内容
快进快退
msec | 目标时间点,单位:毫秒 |
---|---|
accurate | 是否进行精准seek |
IllegalStateException |
---|
快进快退
msec | 目标时间点,单位:毫秒 |
---|
IllegalStateException |
---|
根据流索引开启对应的流, 流索引可通过 getTrackInfo()
获取
trackIndex | 流索引 |
---|
设置播放器缓存数据的最大值,须在prepareAsync()
之前调用
size | 播放器缓存数据的最大值,单位:MB |
---|
设置播放器缓存数据时长的最大阈值,只对直播有效,须在prepareAsync()
之前调用。该值较大,则主播和观众之间延迟较大,该值较小,则对网络波动更敏感,容易引发卡顿
timeSecond | 播放器缓存的最大时长,单位:秒 |
---|
Sets the data source (FileDescriptor) to use. It is the caller's responsibility to close the file descriptor. It is safe to do so as soon as this call returns.
fd | the FileDescriptor for the file you want to play |
---|
IllegalStateException | if it is called in an invalid state |
---|---|
IOException | |
IllegalArgumentException |
Sets the data source (FileDescriptor) to use. The FileDescriptor must be seekable (N.B. a LocalSocket is not seekable). It is the caller's responsibility to close the file descriptor. It is safe to do so as soon as this call returns.
fd | the FileDescriptor for the file you want to play |
---|---|
offset | the offset into the file where the data to be played starts, in bytes |
length | the length in bytes of the data to be played |
IllegalStateException | if it is called in an invalid state |
---|---|
IOException | |
IllegalArgumentException |
Sets the data source (file-path or http/rtsp URL) to use.
path | the path of the file, or the http/rtsp URL of the stream you want to play |
---|
IllegalStateException | if it is called in an invalid state
When |
---|---|
IOException | |
IllegalArgumentException | |
SecurityException |
Sets the data source as a content Uri.
context | the Context to use when resolving the Uri |
---|---|
uri | the Content URI of the data you want to play |
IllegalStateException | if it is called in an invalid state |
---|---|
IOException | |
IllegalArgumentException | |
SecurityException |
Sets the data source as a content Uri.
context | the Context to use when resolving the Uri |
---|---|
uri | the Content URI of the data you want to play |
headers | 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. |
IllegalStateException | if it is called in an invalid state |
---|---|
IOException | |
IllegalArgumentException | |
SecurityException |
IllegalArgumentException | |
---|---|
SecurityException | |
IllegalStateException |
设置播放器的解码类型,须在prepareAsync()
之前调用
mode | 参见KSYMediaPlayer.KSYDecodeMode
|
---|
设置反交错的模式,须使用点播库方可生效
mode | 可参见KSYMediaPlayer.KSYDeinterlaceMode
|
---|
Sets the SurfaceHolder
to use for displaying the video portion of
the media.
Either a surface holder or surface must be set if a display or video sink
is needed. Not calling this method or setSurface(Surface)
when
playing back a video will result in only the audio track being played. A
null surface holder or surface will result in only the audio track being
played.
sh | the SurfaceHolder to use for video display |
---|
Sets the player to be looping or non-looping.
looping | whether to loop or not |
---|
设置视频镜像显示
mirror | true和false分别指镜像显示和正常显示 |
---|
由金山云引入, 设置可播放的范围,仅对点播有效 调用此接口时, 需注意: 1. startTime和endTime中必有一值大于0 2. 当endTime大于0时, 其值必须大于startTime 当以上任一条件不满足时会有IllegalArgumentException抛出
startTime | 起始播放时间点, 单位为毫秒(MS) |
---|---|
endTime | 结束播放时间点, 单位为毫秒(MS) |
设置播放器是否禁音
mute | 1和0分别指播放禁音和不禁音 |
---|
设置旋转角度,旋转方向为逆时针
degree | 旋转角度,只能为 0/90/180/270 中的某个值 |
---|
设置在播放视频时是否保持屏幕常亮
必须在setDisplay(SurfaceHolder)
之后调用方可生效
screenOn | true保持屏幕常量,false则反之 |
---|
设置播放速度
speed | 目标播放速度 |
---|
Sets the Surface to be used as the sink for the video portion of
the media. This is similar to setDisplay(SurfaceHolder)
, but
does not support setScreenOnWhilePlaying(boolean)
. Setting a
Surface will un-set any Surface or SurfaceHolder that was previously set.
A null surface will result in only the audio track being played.
If the Surface sends frames to a SurfaceTexture
, the timestamps
returned from SurfaceTexture
will have an
unspecified zero point. These timestamps cannot be directly compared
between different media sources, different instances of the same media
source, or multiple runs of the same program. The timestamp is normally
monotonically increasing and is unaffected by time-of-day adjustments,
but it is reset when the position is set.
surface | The Surface to be used for the video portion of the media. |
---|
设置准备和读数据超时阈值,需在prepareAsync()
之前调用方可生效
prepareTimeout | 准备超时阈值,即播放器在建立链接、解析流媒体信息的超时阈值 |
---|---|
readTimeout | 读数据超时阈值 |
设置视频的水平和垂直方向的平移量。以手机屏幕中心为原点建立坐标轴,横纵轴坐标各自平行于手机屏幕边缘。归一化处理后,手机屏幕的坐标取值范围为[-1.0, 1.0]
仅在VIDEO_SCALING_MODE_SCALE_TO_FIT
模式下本接口方可生效
horizontal | 水平方向的平移量,范围为 -1.0至1.0,大于0表示水平向右移动,反之则水平向左移动 |
---|---|
vertical | 垂直方向的平移量,范围为 -1.0至1.0,大于0表示垂直向上移动,反之则垂直向下移动 |
设置当前是否由播放器渲染视频内容,与获取视频内容的回调接口KSYMediaPlayer.OnVideoRawDataListener
相结合使用
mode | 1和0分别指让播放器渲染和不渲染视频内容 |
---|
设置播放器视频缩放模式
mode | 播放器缩放模式,可参见VIDEO_SCALING_MODE_SCALE_TO_FIT ,VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING 和VIDEO_SCALING_MODE_NOSCALE_TO_FIT
|
---|
设置当前播放音频,范围为 0.0f -- 1.0f,左右声道的音量建议一致
leftVolume | 左声道音量 |
---|---|
rightVolume | 右声道音量 |
重置播放器,但是不会清除屏幕内容
开始播放视频
IllegalStateException |
---|
停止播放视频
IllegalStateException |
---|
Throwable |
---|