IjkPlayer视频播放
程序员文章站
2022-03-09 20:15:39
...
导依赖
implementation 'com.github.leifzhang:IjkLib:0.4.3'
权限
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
xml布局
<tv.danmaku.ijk.media.widget.media.IjkVideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="300dp"></tv.danmaku.ijk.media.widget.media.IjkVideoView>
代码
IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkplayer.so");
AndroidMediaController controller=new AndroidMediaController(this,false);
videoView.setMediaController(controller);
String url="http://ips.ifeng.com/video19.ifeng.com/video09/2014/06/16/1989823-102-086-0009.mp4";
videoView.setVideoURI(Uri.parse(url));
videoView.start();
//在生命周期中设置 暂停
@Override
protected void onPause() {
super.onPause();
videoView.pause();
}
@Override
protected void onResume() {
super.onResume();
videoView.resume();
}
@Override
protected void onDestroy() {
super.onDestroy();
IjkMediaPlayer.native_profileEnd();
}