IJKPlayer Videos

Video effect:write picture description here

1. Add the following code to the project's build.gradle

allprojects {
        repositories {
            maven { url "https://jitpack.io" }
        }
    }

write picture description here

2. Add dependencies in Module's build.gradle

 compile 'com.github.open-android:IjkPlayer:1.0.0'

3. Copy the following code to xml

<com.dl7.player.media.IjkPlayerView
    android:id="@+id/player_view"
    android:layout_width="match_parent"
    android:layout_height="200dp"/>

4. Copy the following code to Activity

 mPlayerView =(IjkPlayerView)

    findViewById(R.id.player_view);

    mUri =Uri.parse("http://covertness.qiniudn"+".com/android_zaixianyingyinbofangqi_test_baseline.mp4"); 
    mPlayerView.init()

    .setVideoPath(mUri) 

    .setMediaQuality(IjkPlayerView.MEDIA_QUALITY_HIGH) .

    .enableDanmaku() 

    start();

5. Bind the player's life cycle to the Activty life cycle

   @Override
    protected void onResume() {
        super.onResume();
        mPlayerView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mPlayerView.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPlayerView.onDestroy();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mPlayerView.configurationChanged(newConfig);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (mPlayerView.handleVolumeKey(keyCode)) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onBackPressed() {
        if (mPlayerView.onBackPressed()) {
            return;
        }
        super.onBackPressed();
    }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325686297&siteId=291194637