Android使用视频播放器的流程介绍

龙旋

共 1613字,需浏览 4分钟

 · 2021-04-08

视频播放器功能相对来说还是比较常见的功能,如果自己写的话可能需要花费比较多的时间,今天就给大家介绍第三方库NurVideoPlayer,使用还是比较方便的。


支持屏幕滑动--滑动时间,亮度,声音,支持全屏-单屏,双击暂停--继续,锁定屏幕



使用

1、不要忘记项目的根build.gradle配置

allprojects {    repositories {        ...        maven { url 'https://jitpack.io' }    }}


2、使用前需要先在项目中添加OkHttp的依赖库


使用最新版本地址: 

https://jitpack.io/#nurApplication/NurVideoPlayer/1.0.7

implementation 'com.gitee.nurApplication:NurVideoPlayer:1.0.7'


3、添加网络权限

<uses-permission android:name="android.permission.INTERNET"/>


xml

<com.nurmemet.nur.nurvideoplayer.NurVideoPlayer        android:id="@+id/videoView"        android:layout_width="match_parent"        android:layout_height="match_parent"        app:video_height="200dp" />
android:layout_height= 一定要"match_parent"

参数xml中只有一个app:video_height也就是视频播放器的高度,默认值"match_parent"



第一张图app:video_height="200dp"
第二张图-默认


代码:

        String url = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4";        nurVideoPlayer = findViewById(R.id.videoView);        nurVideoPlayer.setUp(this, url, "this is video name");        nurVideoPlayer.start();


参数


return方法注释作用
voidsetUp(Activity activity, String url, String videoName)url视频的地址,videoName初始化
voidstart();
开始播放
voidpause();
暂停
voidresume();
继续
voidsetChangeScreen(boolean fullScreen)fullScreen=true>全屏更改-(全屏-单屏)
voidsetOnBackPress(OnBackPressListener onBackPressListener)没有调用就不会显示(🔙)点击返回按钮
voidsetMonoMode(@NonNull MonoMode mode)NORMAL LEFT_CHANNEL RIGHT_CHANNEL单声道模式
voidseekTo(int msec);msec---time进度
ImageViewgetThumbImageView();你可以用把返回的imageView设置视频的封面封面


到这里就完成了。


浏览 15
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报