怎么在Android中使用GSYVideoPlayer播放视频器

  介绍

怎么在Android中使用GSYVideoPlayer播放视频器?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

GSYVideoPlayer

GSYVideoPlayer官方地址

GSYVideoPlayer一个基于IJkPlayer的播放器
支持调节声音亮度
边播边缓存使用了AndroidVideoCache; ExoPlayer使用SimpleCache
支持多种协议h363 4 \ \ 5, Https, concat、rtsp, hls, rtmp,加密,mpeg等等
简单滤镜(马赛克,黑白,色彩过滤,高斯,模糊,模糊等等20多种),动画,(水印,画面多重播放等)
视频第一帧,视频帧截图功能,视频生成gif功能。
调整显示比例:默认,4:3,16:9的,填充,播放时旋转画面角度(0,90180270);镜像旋转
IJkPlayer, ExoPlayer,媒体播放器切换,自定义内核
小窗口,多窗体下(包括桌面)的小窗口播放。
片头广告,跳过广告支持,中间插入广告功能。
暂停前后台切换不黑屏;调整不同清晰度的支持,无缝切换支持;锁定/解锁全屏点击功能,进度条小窗口预览
可自定义渲染层,自定义管理层,自定义播放层(控制层),自定义缓存层

使用依赖

1, JCenter引入方法(推荐)
你可以选择下面三种的其中一种,在模块下的构建。gradle添加。

,直接引入

//完整版引入   implementation  & # 39; com.shuyu: GSYVideoPlayer: 8.1.2& # 39;

B,添加java和你想要的所以支持:

implementation  & # 39; com.shuyu: gsyVideoPlayer-java: 8.1.2& # 39;//是否需要ExoPlayer模式   implementation  & # 39; com.shuyu: GSYVideoPlayer-exo2:8.1.2& # 39;//根据你的需求ijk模式的   implementation  & # 39; com.shuyu: gsyVideoPlayer-armv5:8.1.2& # 39;   implementation  & # 39; com.shuyu: gsyVideoPlayer-armv7a: 8.1.2& # 39;   implementation  & # 39; com.shuyu: gsyVideoPlayer-arm64:8.1.2& # 39;   implementation  & # 39; com.shuyu: gsyVideoPlayer-x64:8.1.2& # 39;   implementation  & # 39; com.shuyu: gsyVideoPlayer-x86:8.1.2& # 39;

C,支持其他格式协议的(mpeg、rtsp concat、加密协议)

implementation  & # 39; com.shuyu: gsyVideoPlayer-java: 8.1.2& # 39;//是否需要ExoPlayer模式   implementation  & # 39; com.shuyu: GSYVideoPlayer-exo2:8.1.2& # 39;//更多ijk的编码支持   implementation  & # 39; com.shuyu: gsyVideoPlayer-ex_so: 8.1.2& # 39;

代码中的全局切换支持

//EXOPlayer内核,支持格式更多   PlayerFactory.setPlayManager (Exo2PlayerManager.class);//系统内核模式   PlayerFactory.setPlayManager (SystemPlayerManager.class);//ijk内核,默认模式   PlayerFactory.setPlayManager (IjkPlayerManager.class);//挂式缓存模式,支持m3u8,只支持精彩   CacheFactory.setCacheManager (ExoPlayerCacheManager.class);//代理缓存模式,支持所有模式,不支持m3u8等,默认   CacheFactory.setCacheManager (ProxyCacheManager.class);//切换渲染模式   GSYVideoType.setShowType (GSYVideoType.SCREEN_MATCH_FULL);//默认显示比例   时间=GSYVideoType.SCREEN_TYPE_DEFAULT  0;//16:9   时间=GSYVideoType.SCREEN_TYPE_16_9  1;//4:3   GSYVideoType.SCREEN_TYPE_4_3 =, 2;//全屏裁减显示,为了显示正常,CoverImageView 建议使用FrameLayout作为父布的局   GSYVideoType.SCREEN_TYPE_FULL =, 4;//全屏拉伸显示,使用这个属性时,surface_container建议使用FrameLayout   GSYVideoType.SCREEN_MATCH_FULL =, 4;/* * *   ,* SCREEN_TYPE_CUSTOM 下自定义显示比例   ,* @param  screenScaleRatio 高宽比,如,16:9   ,*/public  static  void  setScreenScaleRatio (float  screenScaleRatio)//切换绘制模式   GSYVideoType.setRenderType (GSYVideoType.SUFRACE);   GSYVideoType.setRenderType (GSYVideoType.GLSURFACE);   GSYVideoType.setRenderType (GSYVideoType.TEXTURE);//ijk关闭日志   IjkPlayerManager.setLogLevel (IjkMediaPlayer.IJK_LOG_SILENT);//exoplayer自定义MediaSource   ExoSourceManager.setExoMediaSourceInterceptListener (new  ExoMediaSourceInterceptListener (), {   @Override才能   public 才能;MediaSource  getMediaSource (String 数据源,boolean 预览,,boolean  cacheEnable,, boolean  isLooping,, File  cacheDir), {   ,,,//可自定义MediaSource   ,,,return 零;   ,,}   });

自定义一个播放器

public  class  LiveVideo  extends  StandardGSYVideoPlayer  {   public 才能;LiveDataFullscreenButtonClick  liveDataClick;//点击全屏按钮回调      ,/* *   ,,*,恢复暂停状态   ,,*/public 才能;void  onResume (), {   ,,,onVideoResume ();   ,,}   ,/* *   ,,*,暂停状态   ,,*/public 才能;void  onPause (), {   ,,,onVideoPause ();   ,,}      ,/* *   ,,*,接口回调   ,,*,@param  liveDataClick   ,,*/public 才能;void  setOnFullscreenButtonClick (LiveDataFullscreenButtonClick  liveDataClick), {   ,,,this.liveDataClick =, liveDataClick;   ,,}/*,才能重写方法自定义layout  id与video_layout_standard.xml一致,不重新使用系统默认布局*/@Override才能   public 才能;int  getLayoutId (), {   ,,,return  R.layout.test;   ,,}      public 才能;LiveVideo (Context 上下文,Boolean  fullFlag), {   ,,,超级(上下文,fullFlag);   ,,,init ();   ,,}      public 才能LiveVideo (Context 上下文),{   ,,,超级(上下文);   ,,,init ();   ,,}      public 才能;LiveVideo (Context 上下文,AttributeSet  attrs), {   ,,,超级(上下文,attrs);   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

怎么在Android中使用GSYVideoPlayer播放视频器