}
IMeidaPlayerProxy
定义MeidaPlayer的代理接口,所有MediaPlayer的代理必须实现newInstance接口创建MediaPlayer。
interface IMediaPlayerProxy {
IMediaPlayer newInstance();
}
IjkPlayer的MediaPlayer的代理
在使用IjkPlayer之前需要添加依赖,并且将编译好的so库添加到项目中的jniLibs下。
//添加ijkplayer依赖
dependencies {
compile ‘tv.danmaku.ijk.media:ijkplayer-java:0.8.4’
compile ‘tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.4’
compile ‘tv.danmaku.ijk.media:ijkplayer-x86:0.8.4’
}
//IjkMediaPlayer代理,实现IMediaPlayer接口
public class IjkMediaPlayerProxy implements IMediaPlayerProxy, IMediaPlayer {
//声明一个IjkMediaPlayer对象
private IjkMediaPlayer mIjkMediaPlayer;
@Override
public IMediaPlayer newInstance() {
//创建IjkMeidaPlayer对象
mIjkMediaPlayer = new IjkMediaPlayer();
return this;
}
@Override
public void prepareAsync() throws IllegalStateException {
mIjkMediaPlayer.prepareAsync();
}
@Override
public void start() throws IllegalStateException {
mIjkMediaPlayer.start();
}
@Override
public void stop() throws IllegalStateException {
mIjkMediaPlayer.stop();
}
…
}
PLDroidPlayer的MediaPlayer代理
在使用PLMediaPlayer之前参考[官方文档](()集成PLDroidPlayer
//PLMediaPlayer代理,实现IMediaPlayer接口
public class PLMediaPlayerProxy implements IMediaPlayerProxy, IMediaPlayer {
//定义PLMediaPlayer对象
private PLMediaPlayer mMediaPlayer;
//AVOptions为MediaPlayer的选项配置,例如可以配置开启硬解码
private AVOptions mAvOptions;
@Override
public IMediaPlayer newInstance() {
//创建PLDroidPlayer的PLMediaPlayer对象
mMediaPlayer = new PLMediaPlayer(mContext, mAvOptions);
return this;
}
@Override
public void prepareAsync() throws IllegalStateException {
mMediaPlayer.prepareAsync();
}
@Override
public void start() throws IllegalStateException {
mMediaPlayer.start();
}
@Override
public void stop() throws IllegalStateException {
mMediaPlayer.stop();
}
…
}
VideoView
VideoView仿照原生VideoView的实现