实现demo:https://download.csdn.net/download/meixi_android/13729352
获取视频时长
delyedTime = videoView.getDuration();//单位毫秒(ms)
引入视频模块
implementation project(':dkplayer-java')
implementation project(':dkplayer-ui')
视频View
<com.dueeeke.videoplayer.player.VideoViewandroid:id="@+id/player"android:layout_width="match_parent"android:layout_height="wrap_content"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" />
实现activity
/*** @author : LGQ* @date : 2020/12/19 09* @desc :*/
public class PlayVideoActivity extends Activity {VideoView mVideoView;@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_play_video);mVideoView = findViewById(R.id.player);StandardVideoController controller = new StandardVideoController(this);//根据屏幕方向自动进入/退出全屏controller.setEnableOrientation(true);controller.addControlComponent(new CompleteView(this));//自动完成播放界面VodControlView vodControlView = new VodControlView(this);//点播控制条controller.addControlComponent(vodControlView);//根据是否为直播决定是否需要滑动调节进度controller.setCanChangePosition(false);//如果你不想要UI,不要设置控制器即可mVideoView.setVideoController(controller);
// mVideoView.setUrl("http://vfx.mtime.cn/Video/2019/03/14/mp4/190314223540373995.mp4");mVideoView.setUrl("http://szhdljhsxshg.app.xiaozhuschool.com/uploads/20201022/2dd814eb3ad4a50335346f29306204e4.mp4");mVideoView.start();}private VideoView.OnStateChangeListener mOnStateChangeListener = new VideoView.SimpleOnStateChangeListener() {@Overridepublic void onPlayerStateChanged(int playerState) {switch (playerState) {case VideoView.PLAYER_NORMAL://小屏break;case VideoView.PLAYER_FULL_SCREEN://全屏break;}}@Overridepublic void onPlayStateChanged(int playState) {switch (playState) {case VideoView.STATE_IDLE:break;case VideoView.STATE_PREPARING://在STATE_PREPARING时设置setMute(true)可实现静音播放
// mVideoView.setMute(true);break;case VideoView.STATE_PREPARED:break;case VideoView.STATE_PLAYING://需在此时获取视频宽高int[] videoSize = mVideoView.getVideoSize();L.d("视频宽:" + videoSize[0]);L.d("视频高:" + videoSize[1]);break;case VideoView.STATE_PAUSED:break;case VideoView.STATE_BUFFERING:break;case VideoView.STATE_BUFFERED:break;case VideoView.STATE_PLAYBACK_COMPLETED:break;case VideoView.STATE_ERROR:break;}}};@Overrideprotected void onPause() {super.onPause();if (mVideoView != null) {mVideoView.pause();}}
}