jjdxm-ijkPlayer开源视频框架简单的日常使用

来源:互联网 发布:叮叮聊天软件 编辑:程序博客网 时间:2024/06/08 11:34

jjdxm-ijkPlayer开源视频框架简单的日常使用

一.前提申明:
1.转自开源贡献者jjdxmashl 点击这里查看github源地址
2.开发环境:as
3.jjdxm-ijkPlayer版本1.0.6(这里请注意1.0.6版本之后PlayerView的构造方法改变了)

二.步骤
1.导入依赖包
compile ‘com.dou361.ijkplayer:jjdxm-ijkplayer:x.x.x’
历史版本:
compile ‘com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.6’
compile ‘com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.5’
compile ‘com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.4’
compile ‘com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.3’
compile ‘com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.2’
compile ‘com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.1’
compile ‘com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.0’

2.代码中的使用
注意配置生命周期方法. 为了让播放器同步Activity生命周期,建议以下方法都去配置,注释的代码,主要作用是播放时屏幕常亮和暂停其它媒体的播放。这里注意我初次使用的时候没有去重写onConfigurationChanged()方法,导致不能全屏。(需要同时配置manifest的activity属性)

<activity android:name=".MainActivity"          android:configChanges="orientation|screenSize"/>
public class MainActivity extends AppCompatActivity {    private PlayerView mPlayer;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        View rootView = getLayoutInflater().from(this).inflate(R.layout.activity_main, null);        setContentView(rootView);        String url = "http://9890.vod.myqcloud.com/9890_9c1fa3e2aea011e59fc841df10c92278.f20.mp4";        setContentView(rootView);        mPlayer = new PlayerView(this,rootView)                .setScaleType(PlayStateParams.fitparent)                .hideMenu(true)                .forbidTouch(false)                .setForbidHideControlPanl(false)                .hideCenterPlayer(false)                .showThumbnail(new OnShowThumbnailListener() {                    @Override                    public void onShowThumbnail(ImageView ivThumbnail) {                        /**加载前显示的缩略图*/                        Glide.with(MainActivity.this)                                .load("http://pic2.nipic.com/20090413/406638_125424003_2.jpg")                                .placeholder(R.color.colorAccent)                                .error(R.color.colorPrimaryDark)                                .into(ivThumbnail);                    }                })                .setPlaySource(url)                .startPlay();    }    @Override    protected void onPause() {        super.onPause();        if (mPlayer != null) {            mPlayer.onPause();        }        /**demo的内容,恢复系统其它媒体的状态*/        //MediaUtils.muteAudioFocus(mContext, true);    }    @Override    protected void onResume() {        super.onResume();        if (mPlayer != null) {            mPlayer.onResume();        }        /**demo的内容,暂停系统其它媒体的状态*/        //MediaUtils.muteAudioFocus(mContext, false);        /**demo的内容,激活设备常亮状态*/        //if (wakeLock != null) {        //    wakeLock.acquire();        //}    }    @Override    protected void onDestroy() {        super.onDestroy();        if (mPlayer != null) {            mPlayer.onDestroy();        }    }    @Override    public void onConfigurationChanged(Configuration newConfig) {        super.onConfigurationChanged(newConfig);        if (mPlayer != null) {            mPlayer.onConfigurationChanged(newConfig);        }    }    @Override    public void onBackPressed() {        if (mPlayer != null && mPlayer.onBackPressed()) {            return;        }        super.onBackPressed();        /**demo的内容,恢复设备亮度状态*/        //if (wakeLock != null) {        //    wakeLock.release();        //}    }}

ok,至此相信已经能在你的项目中跑起来了。你还可以自定义View,但注意已有的字段id尽量不要去改变。
还有更多的属性配置参考这里 github源地址。

                                            wirte by Gee @2017年11月30日17点14分
阅读全文
0 0