Operation effect
Supporting video:
http://toutiao.com/item/6431719005085499906/
Using steps
1. Add the following code to build.gradle of the project (as shown below)
allprojects { repositories { ... maven { url "https://jitpack.io" } } }
2. Add dependency in the 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 life cycle of player and activity
@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(); }
Author: Ma weiqi
Link: https://www.jianshu.com/p/c6620e27a67a
Source: Jianshu
The copyright of the brief book belongs to the author. For any reprint, please contact the author for authorization and indicate the source.