最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android GSYVideoPlayer視頻播放器功能的實(shí)現(xiàn)

 更新時(shí)間:2021年03月31日 11:25:32   作者:Android_零零七  
這篇文章主要介紹了Android GSYVideoPlayer視頻播放器功能的實(shí)現(xiàn),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

GSYVideoPlayer

GSYVideoPlayer官方地址

GSYVideoPlayer 一個(gè)基于IJkPlayer的播放器
支持調(diào)節(jié)聲音亮度
邊播邊緩存 使用了AndroidVideoCache;ExoPlayer使用SimpleCache
支持多種協(xié)議h263\4\5、Https、concat、rtsp、hls、rtmp、crypto、mpeg等等
簡(jiǎn)單濾鏡(馬賽克、黑白、色彩過濾、高斯、模糊、模糊等等20多種)、動(dòng)畫、(水印、畫面多重播放等)
視頻第一幀、視頻幀截圖功能,視頻生成gif功能。
調(diào)整顯示比例:默認(rèn)、16:9、4:3、填充;播放時(shí)旋轉(zhuǎn)畫面角度(0,90,180,270);鏡像旋轉(zhuǎn)
IJKPlayer、EXOPlayer、MediaPlayer切換、自定義內(nèi)核
小窗口、多窗體下(包括桌面)的小窗口播放。
片頭廣告、跳過廣告支持、中間插入廣告功能。
暫停前后臺(tái)切換不黑屏;調(diào)整不同清晰度的支持;無縫切換支持;鎖定/解鎖全屏點(diǎn)擊功能;進(jìn)度條小窗口預(yù)覽
可自定義渲染層、自定義管理層、自定義播放層(控制層)、自定義緩存層

使用依賴

1、JCenter 引入方法(推薦)
你可以選擇下面三種的其中一種,在module下的build.gradle添加。

A、直接引入

//完整版引入
implementation 'com.shuyu:GSYVideoPlayer:8.1.2'

B、添加java和你想要的so支持:

implementation 'com.shuyu:gsyVideoPlayer-java:8.1.2'

//是否需要ExoPlayer模式
implementation 'com.shuyu:GSYVideoPlayer-exo2:8.1.2'

//根據(jù)你的需求ijk模式的so
implementation 'com.shuyu:gsyVideoPlayer-armv5:8.1.2'
implementation 'com.shuyu:gsyVideoPlayer-armv7a:8.1.2'
implementation 'com.shuyu:gsyVideoPlayer-arm64:8.1.2'
implementation 'com.shuyu:gsyVideoPlayer-x64:8.1.2'
implementation 'com.shuyu:gsyVideoPlayer-x86:8.1.2'

C、支持其他格式協(xié)議的(mpeg,rtsp, concat、crypto協(xié)議)

implementation 'com.shuyu:gsyVideoPlayer-java:8.1.2'

//是否需要ExoPlayer模式
implementation 'com.shuyu:GSYVideoPlayer-exo2:8.1.2'

//更多ijk的編碼支持
implementation 'com.shuyu:gsyVideoPlayer-ex_so:8.1.2'

代碼中的全局切換支持

//EXOPlayer內(nèi)核,支持格式更多
PlayerFactory.setPlayManager(Exo2PlayerManager.class);
//系統(tǒng)內(nèi)核模式
PlayerFactory.setPlayManager(SystemPlayerManager.class);
//ijk內(nèi)核,默認(rèn)模式
PlayerFactory.setPlayManager(IjkPlayerManager.class);


//exo緩存模式,支持m3u8,只支持exo
CacheFactory.setCacheManager(ExoPlayerCacheManager.class);
//代理緩存模式,支持所有模式,不支持m3u8等,默認(rèn)
CacheFactory.setCacheManager(ProxyCacheManager.class);



//切換渲染模式
GSYVideoType.setShowType(GSYVideoType.SCREEN_MATCH_FULL);
//默認(rèn)顯示比例
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;
//全屏拉伸顯示,使用這個(gè)屬性時(shí),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關(guān)閉log
IjkPlayerManager.setLogLevel(IjkMediaPlayer.IJK_LOG_SILENT);


//exoplayer自定義MediaSource
ExoSourceManager.setExoMediaSourceInterceptListener(new ExoMediaSourceInterceptListener() {
  @Override
  public MediaSource getMediaSource(String dataSource, boolean preview, boolean cacheEnable, boolean isLooping, File cacheDir) {
    //可自定義MediaSource
    return null;
  }
});

自定義一個(gè)播放器

public class LiveVideo extends StandardGSYVideoPlayer {
  public LiveDataFullscreenButtonClick liveDataClick;//點(diǎn)擊全屏按鈕回調(diào)

  /**
   * 恢復(fù)暫停狀態(tài)
   */
  public void onResume() {
    onVideoResume();
  }
  /**
   * 暫停狀態(tài)
   */
  public void onPause() {
    onVideoPause();
  }

  /**
   * 接口回調(diào)
   * @param liveDataClick
   */
  public void setOnFullscreenButtonClick(LiveDataFullscreenButtonClick liveDataClick) {
    this.liveDataClick = liveDataClick;
  }

  /* 重寫方法自定義layout id與video_layout_standard.xml一致 不重新使用系統(tǒng)默認(rèn)布局*/
  @Override
  public int getLayoutId() {
    return R.layout.test;
  }

  public LiveVideo(Context context, Boolean fullFlag) {
    super(context, fullFlag);
    init();
  }

  public LiveVideo(Context context) {
    super(context);
    init();
  }

  public LiveVideo(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
  }

  /* 初始化操作 */
  private void init() {
    //EXOPlayer內(nèi)核,支持格式更多
//    PlayerFactory.setPlayManager(Exo2PlayerManager.class);
    //代理緩存模式,支持所有模式,不支持m3u8等,默認(rèn)
//    CacheFactory.setCacheManager(ProxyCacheManager.class);
    //系統(tǒng)內(nèi)核模式
//    PlayerFactory.setPlayManager(SystemPlayerManager.class);
    //ijk內(nèi)核,默認(rèn)模式
    PlayerFactory.setPlayManager(IjkPlayerManager.class);
    settingsVideo();
  }
  /* 一些播放器的設(shè)置 做一些UI的隱藏 可根據(jù)自己需求*/
  public void settingsVideo() {
    GSYVideoType.enableMediaCodec();//使能硬解碼,播放前設(shè)置
    Debuger.enable();//打開GSY的Log
    //隱藏一些UI
    setViewShowState(mBottomContainer, VISIBLE);
    setViewShowState(mTopContainer, VISIBLE);
    setViewShowState(mLockScreen, GONE);
    setViewShowState(mLoadingProgressBar, GONE);
    setViewShowState(mTopContainer, GONE);
    setViewShowState(mThumbImageView, GONE);
    setViewShowState(mBottomProgressBar, GONE);
    //顯示一些UI  進(jìn)度 時(shí)間 當(dāng)前時(shí)間 全屏 返回 加載Loading 暫停開始
    setViewShowState(mStartButton, VISIBLE);
    setViewShowState(mLoadingProgressBar, VISIBLE);
    setViewShowState(mFullscreenButton, VISIBLE);
    setViewShowState(mBackButton, GONE);
    setViewShowState(mProgressBar, VISIBLE);
    setViewShowState(mCurrentTimeTextView, VISIBLE);
    setViewShowState(mTotalTimeTextView, VISIBLE);
    setEnlargeImageRes(R.drawable.full);
    setShrinkImageRes(R.drawable.full);
  }

  //攔截事件
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    mFullscreenButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View view) {
        liveDataClick.onClick();
      }
    });
    return super.dispatchTouchEvent(ev);
  }

  /* 取消 雙擊暫停 */
  @Override
  protected void touchDoubleUp() {
//    super.touchDoubleUp();
  }

  public interface LiveDataFullscreenButtonClick {
    void onClick();
  }
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@android:color/black">
  <RelativeLayout
    android:id="@+id/surface_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">
  </RelativeLayout>
  <RelativeLayout
    android:id="@+id/thumb"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:background="#000000"
    android:scaleType="fitCenter" />
  <LinearLayout
    android:id="@+id/layout_bottom"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_alignParentBottom="true"
    android:background="#99000000"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:visibility="invisible">
    <TextView
      android:id="@+id/current"
      android:textColor="@color/white"
      style="@style/news_des_style"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="16dp"
      android:text="00:00"
    />
    
    <SeekBar
      android:id="@+id/progress"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_gravity="center_vertical"
      android:layout_weight="1.0"
      android:background="@null"
      android:padding="10dp"
      android:max="100"
      android:maxHeight="4dp"
      android:minHeight="4dp"
      android:paddingBottom="8dp"
      android:paddingTop="8dp"
      android:progressDrawable="@drawable/video_progress_bg"
      android:thumb="@drawable/video_seek_thumb" />
    <TextView
      android:id="@+id/total"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginRight="16dp"
      android:text="00:00"
      android:textColor="@color/white"
      style="@style/news_des_style"/>
  </LinearLayout>
  <LinearLayout
    android:id="@+id/layout_top"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:background="@drawable/video_title_bg"
    android:gravity="center_vertical">
    <ImageView
      android:id="@+id/back"
      android:layout_width="48dp"
      android:layout_height="48dp"
      android:paddingLeft="10dp"
      android:scaleType="centerInside"
      android:src="@drawable/video_back" />
      <View
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="match_parent"/>
    <ImageView
      android:id="@+id/fullscreen"
      style="@style/left_icon_style"
      android:src="@drawable/full" />
  </LinearLayout>
  <ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/loading"
    android:layout_centerInParent="true"
    />
  <ImageView
    android:visibility="gone"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_centerInParent="true"
    android:padding="5dp"
    android:id="@+id/start"
   />
</RelativeLayout>

api

/**
   * 設(shè)置播放URL
   *
   * @param url      播放url
   * @param cacheWithPlay 是否邊播邊緩存
   * @param title     title
   * @return
   */
video.setUp("url", false, "");//設(shè)置播放路徑
video.startPlayLogic();//開始播放

在這里插入圖片描述
在這里插入圖片描述

到此這篇關(guān)于Android GSYVideoPlayer視頻播放器功能的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Android GSYVideoPlayer視頻播放器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

东辽县| 镇江市| 正定县| 巴塘县| 淮北市| 西林县| 临安市| 南城县| 来安县| 灵宝市| 南部县| 宜兰县| 布尔津县| 古田县| 桂阳县| 荆门市| 长泰县| 保德县| 兰西县| 九台市| 汉阴县| 安徽省| 隆德县| 徐闻县| 尼勒克县| 岳阳市| 静海县| 北票市| 呈贡县| 鸡泽县| 浏阳市| 镇宁| 仙居县| 宜兴市| 林州市| 通州市| 邛崃市| 遂溪县| 营口市| 玉林市| 错那县|