-
Notifications
You must be signed in to change notification settings - Fork 1k
Home
dueeeke edited this page Jul 8, 2019
·
44 revisions
建议使用之前先把demo跑一下,我对很多使用姿势都进行了演示
gradle
dependencies {
# 必选,内部默认使用系统mediaplayer进行解码
implementation 'com.github.dueeeke.dkplayer:dkplayer-java:3.0.2'
# 可选,包含StandardVideoController的实现
implementation 'com.github.dueeeke.dkplayer:dkplayer-ui:3.0.2'
# 可选,使用exoplayer进行解码
implementation 'com.github.dueeeke.dkplayer:player-exo:3.0.2'
# 可选,使用ijkplayer进行解码
implementation 'com.github.dueeeke.dkplayer:player-ijk:3.0.2'
implementation 'com.github.dueeeke.dkplayer:ijk-armv7a:3.0.2'
implementation 'com.github.dueeeke.dkplayer:ijk-armv5:3.0.2'
implementation 'com.github.dueeeke.dkplayer:ijk-arm64:3.0.2'
implementation 'com.github.dueeeke.dkplayer:ijk-x86:3.0.2'
implementation 'com.github.dueeeke.dkplayer:ijk-x86_64:3.0.2'
}
或者将library下载并导入项目中使用
<com.dueeeke.videoplayer.player.VideoView
android:id="@+id/player"
android:layout_width="match_parent"
android:layout_height="300dp" />
videoView.setUrl(URL_VOD); //设置视频地址
StandardVideoController controller = new StandardVideoController(this);
controller.setTitle("网易公开课-如何掌控你的自由时间"); //设置视频标题
videoView.setVideoController(controller); //设置控制器,如需定制可继承BaseVideoController
videoView.start(); //开始播放,不调用则不自动播放
@Override
protected void onPause() {
super.onPause();
videoView.pause();
}
@Override
protected void onResume() {
super.onResume();
videoView.resume();
}
@Override
protected void onDestroy() {
super.onDestroy();
videoView.release();
}
@Override
public void onBackPressed() {
if (!videoView.onBackPressed()) {
super.onBackPressed();
}
}
<activity
android:name=".PlayerActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:screenOrientation="portrait" /> <!-- or android:screenOrientation="landscape"-->
首先需要引入相关依赖,需要注意,播放器内部默认使用系统MediaPlayer进行解码
建议在Application
中调用
VideoViewManager.setConfig(VideoViewConfig.newBuilder()
//使用使用IjkPlayer解码
.setPlayerFactory(IjkPlayerFactory.create(this))
//使用ExoPlayer解码
.setPlayerFactory(ExoMediaPlayerFactory.create(this))
//使用MediaPlayer解码
.setPlayerFactory(AndroidMediaPlayerFactory.create(this))
.build());
调用VideoView
中的setPlayerFactory
方法,需要在start
方法之前调用方可生效
//使用IjkPlayer解码
mVideoView.setPlayerFactory(IjkPlayerFactory.create(this));
//使用ExoPlayer解码
mVideoView.setPlayerFactory(ExoMediaPlayerFactory.create(this));
//使用MediaPlayer解码
mVideoView.setPlayerFactory(AndroidMediaPlayerFactory.create(this));
参考demo ╰( ̄▽ ̄)╭
-keep class com.dueeeke.videoplayer.** { *; }
-dontwarn com.dueeeke.videoplayer.**
# IjkPlayer
-keep class tv.danmaku.ijk.** { *; }
-dontwarn tv.danmaku.ijk.**
#ExoPlayer
-keep class com.google.android.exoplayer2.** { *; }
-dontwarn com.google.android.exoplayer2.**