jjdxm-ijkPlayer開源視頻框架簡單的日常使用

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分
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章