EasyMedia项目简介 视频播放
build.gradle文件中添加:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}并且:
dependencies {
//核心库
implementation 'com.github.ashLikun:EasyMedia:{latest version}'
//使用Ijkplay
implementation 'com.github.CarGuo:GSYIjkJava:1.0.0'
//so文件 后缀带 https 表示支持https 如lite_https
implementation 'com.github.ashLikun.ijkplayer:lite:1.0.0'//最小库
implementation 'com.github.ashLikun.ijkplayer:lite_hevc:1.0.0'//最小库(带hevc)
implementation 'com.github.ashLikun.ijkplayer:default:1.0.0'//最大库(支持格式多)
//Ijkplay
implementation 'com.github.ashLikun.EasyMedia:BaseMedia:2.6.1'
//普通的全部架构
implementation 'com.github.ashLikun.EasyMedia:ijkplayer-all:2.6.1'
//armv5
implementation 'com.github.ashLikun.EasyMedia:ijkplayer-armv5:2.6.1'
//armv7a
implementation 'com.github.ashLikun.EasyMedia:ijkplayer-armv7a:2.6.1'
//armv64
implementation 'com.github.ashLikun.EasyMedia:ijkplayer-armv64:2.6.1'
//x86
implementation 'com.github.ashLikun.EasyMedia:ijkplayer-x86:2.6.1'
//x86_64
implementation 'com.github.ashLikun.EasyMedia:ijkplayer-x86_64:2.6.1'
//支持其他格式协议的(mpeg,rtsp, concat、crypto协议)
implementation 'com.github.ashLikun.EasyMedia:ijkplayer-ex_so:+'
//使用Exo2Play
implementation 'com.github.ashLikun.EasyMedia:BaseMedia:2.6.1'
implementation 'com.github.ashLikun.EasyMedia:ExoPlay2:2.6.1'
implementation 'com.google.android.exoplayer:exoplayer:2.18.7'
//下面两个根据需求
implementation 'com.google.android.exoplayer:extension-rtmp:2.18.7'
implementation 'com.google.android.exoplayer:exoplayer-rtsp:2.18.7'
//Media3
implementation 'com.github.ashLikun.EasyMedia:BaseMedia:2.6.1'
implementation 'com.github.ashLikun.EasyMedia:ExoPlay3:2.6.1'
implementation "androidx.media3:media3-common:$rootProject.ext.media3"
implementation "androidx.media3:media3-exoplayer:$rootProject.ext.media3"
//下面是各种MediaSource ,按需引用
//使用ExoPlayer支持行车记录仪播放
implementation "androidx.media3:media3-exoplayer-dash:$rootProject.ext.media3"
// 使用ExoPlayer支持HLS播放
implementation "androidx.media3:media3-exoplayer-hls:$rootProject.ext.media3"
//SsMediaSource
implementation "androidx.media3:media3-exoplayer-smoothstreaming:$rootProject.ext.media3"
implementation "androidx.media3:media3-exoplayer-rtsp:$rootProject.ext.media3"
implementation "androidx.media3:media3-datasource-rtmp:$rootProject.ext.media3"
} <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<com.ashlikun.media.EasyVideoPlayer
android:id="@+id/mediaPlay"
android:layout_width="match_parent"
android:layout_height="250dp"
app:video_full_screen_enable="false"></com.ashlikun.media.EasyVideoPlayer>
//全局初始化(applicable)
VideoUtils.init(this, EasyVideoExo2.class);
VideoUtils.setMediaInterface(new EasyMediaIjkplayer());//使用ijkplay播放需要引入库
VideoUtils.setMediaInterface(new EasyMediaSystem());//使用原生播放器
也可以自己实现播放器,只需实现EasyMediaInterface接口,然后设置给EasyMedia
//最简单的
mediaPlay.setDataSource(new MediaData.Builder()
.title("标题")
.url(videoUrl)
.builder());
//设置宽高比,内部会根据宽度自动计算高度,也有最大高度限制
videoPlayer.setVideoRatio(s.getWidth(), s.getHeigth());
//直接全屏
VideoUtils.startFullscreen(new EasyVideoPlayer(this), videoUrl, "标题");
//直接全屏 不可竖屏
EasyVideoPlayer easyVideoPlayer = new EasyVideoPlayer(this);
easyVideoPlayer.setFullscreenPortrait(false);
VideoUtils.startFullscreen(easyVideoPlayer, videoUrl, "标题");
//RecyclerView列表
videoPlayer.setVideoRatio(s.getWidth(), s.getHeigth());
videoPlayer.setCurrentScreen(MediaScreenStatus.SCREEN_WINDOW_LIST);
videoPlayer.setDataSource(s.getVideoUrl(), s.getText());
//列表滚动 自动小窗口
recyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {
@Override
public void onChildViewAttachedToWindow(View view) {
EasyVideoPlayer videoPlayer = view.findViewById(R.id.videoPlay);
VideoUtils.onRecyclerAutoTiny(videoPlayer, false);
}
@Override
public void onChildViewDetachedFromWindow(View view) {
EasyVideoPlayer videoPlayer = view.findViewById(R.id.videoPlay);
VideoUtils.onRecyclerAutoTiny(videoPlayer, true);
}
});
//RecyclerView Item不可见时候自动销毁
VideoUtils.onRecyclerRelease(videoPlayer);
//listView 列表滚动时候
VideoUtilsd onScrollReleaseAllVideos(int currentPlayPosition, int firstVisibleItem, int visibleItemCount)
VideoUtilsd onScrollAutoTiny(int currentPlayPosition, int firstVisibleItem, int visibleItemCount)
//显示占位图
GlideUtils.show(videoPlayer.getThumbImageView(), "http://p3.pstatp.com/" + s.getImageUrl());
//生命周期
@Override
public void onBackPressed() {
if (VideoUtils.backPress()) {
return;
}
super.onBackPressed();
}
@Override
protected void onPause() {
super.onPause();
VideoUtils.onPause();
}
@Override
protected void onResume() {
super.onResume();
VideoUtils.onResume();
}
@Override
protected void onDestroy() {
super.onDestroy();
VideoUtils.onDestroy();
}
//之定义播放器样式
1:继承EasyVideoPlayer,从写
public MediaControllerInterface getController() {
return new EasyMediaController(getContext());
}
也可以直接调用initController方法
2:实现自己的EasyMediaController(控制器),可以直接继承EasyMediaController,从写getLayoutId,getControllerViewHolder方法实现控制器界面展示
3:EasyControllerViewHolder 控制器的界面设置类





