android播放器三方库

github链接 https://github.com/CarGuo/GSYVideoPlayer

github有时候死活进不去修改dns也不行  记录一下 以备不时之需(其实就是搬运...小声bb)[dog]

1.使用

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

2.下面三种 选一种

 implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer:v8.1.3-jitpack'
implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-java:v8.1.3-jitpack'

 //是否需要ExoPlayer模式
 implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-exo_player2:v8.1.3-jitpack'

 //根据你的需求ijk模式的so
 implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-armv64:v8.1.3-jitpack'
 implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-armv7a:v8.1.3-jitpack'
 implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-armv5:v8.1.3-jitpack'
 implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-x86:v8.1.3-jitpack'
 implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-x86_64:v8.1.3-jitpack'
implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-java:v8.1.3-jitpack'

 //是否需要ExoPlayer模式
 implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-exo_player2:v8.1.3-jitpack'

 //更多ijk的编码支持
 implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-ex_so:v8.1.3-jitpack'

3 代码中使用

 3.1xml布局添加

<com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
    android:id="@+id/detail_player"
    android:layout_width="match_parent"
    android:layout_height="@dimen/post_media_height" />

 3.2 oncreate中

/外部辅助的旋转,帮助全屏
orientationUtils = new OrientationUtils(this, detailPlayer);
//初始化不打开外部的旋转
orientationUtils.setEnable(false);

GSYVideoOptionBuilder gsyVideoOption = new GSYVideoOptionBuilder();
gsyVideoOption.setThumbImageView(imageView)
        .setIsTouchWiget(true)
        .setRotateViewAuto(false)
        .setLockLand(false)
        .setAutoFullWithSize(true)
        .setShowFullAnimation(false)
        .setNeedLockFull(true)
        .setUrl(url)
        .setCacheWithPlay(false)
        .setVideoTitle("测试视频")
        .setVideoAllCallBack(new GSYSampleCallBack() {
            @Override
            public void onPrepared(String url, Object... objects) {
                super.onPrepared(url, objects);
                //开始播放了才能旋转和全屏
                orientationUtils.setEnable(true);
                isPlay = true;
            }

            @Override
            public void onQuitFullscreen(String url, Object... objects) {
                super.onQuitFullscreen(url, objects);
                Debuger.printfError("***** onQuitFullscreen **** " + objects[0]);//title
                Debuger.printfError("***** onQuitFullscreen **** " + objects[1]);//当前非全屏player
                if (orientationUtils != null) {
                    orientationUtils.backToProtVideo();
                }
            }
        }).setLockClickListener(new LockClickListener() {
            @Override
            public void onClick(View view, boolean lock) {
                if (orientationUtils != null) {
                    //配合下方的onConfigurationChanged
                    orientationUtils.setEnable(!lock);
                }
            }
        }).build(detailPlayer);

detailPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        //直接横屏
        orientationUtils.resolveByClick();

        //第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
        detailPlayer.startWindowFullscreen(SimpleDetailActivityMode2.this, true, true);
    }
});

3.3 配置生命周期

@Override
public void onBackPressed() {
    if (orientationUtils != null) {
        orientationUtils.backToProtVideo();
    }
    if (GSYVideoManager.backFromWindowFull(this)) {
        return;
    }
    super.onBackPressed();
}


@Override
protected void onPause() {
    detailPlayer.getCurrentPlayer().onVideoPause();
    super.onPause();
    isPause = true;
}

@Override
protected void onResume() {
    detailPlayer.getCurrentPlayer().onVideoResume(false);
    super.onResume();
    isPause = false;
}

@Override
protected void onDestroy() {
    super.onDestroy();
    if (isPlay) {
        detailPlayer.getCurrentPlayer().release();
    }
    if (orientationUtils != null)
        orientationUtils.releaseListener();
}



@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    //如果旋转了就全屏
    if (isPlay && !isPause) {
        detailPlayer.onConfigurationChanged(this, newConfig, orientationUtils, true, true);
    }
}

4.更多使用(下面都是全局生效)

//切换内核
//PlayerFactory.setPlayManager(new Exo2PlayerManager());//EXO模式
//PlayerFactory.setPlayManager(new SystemPlayerManager());//系统模式
//PlayerFactory.setPlayManager(new IjkPlayerManager());//ijk模式
//缓存方式
//CacheFactory.setCacheManager(new ExoPlayerCacheManager());//exo缓存模式,支持m3u8,只支持exo
//CacheFactory.setCacheManager(new ProxyCacheManager());//代理缓存模式,支持所有模式,不支持m3u8等

//增加 ExoMediaSourceInterceptListener,方便 Exo 模式下使用自定义的 MediaSource。
ExoSourceManager.setExoMediaSourceInterceptListener(new ExoMediaSourceInterceptListener() {
           /**
            * @param dataSource  链接
            * @param preview     是否带上header,默认有header自动设置为true
            * @param cacheEnable 是否需要缓存
            * @param isLooping   是否循环
            * @param cacheDir    自定义缓存目录
            * @return 返回不为空时,使用返回的自定义mediaSource
            */
            @Override
            public MediaSource getMediaSource(String dataSource, boolean preview, boolean cacheEnable, boolean isLooping, File cacheDir) {
                return null;
            }
});
//切换比例
//默认显示比例
GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_DEFAULT);
    
//16:9 
GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_16_9);

//全屏裁减显示,为了显示正常 CoverImageView 建议使用FrameLayout作为父布局
GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_FULL);

//全屏拉伸显示,使用这个属性时,surface_container建议使用FrameLayout
GSYVideoType.setShowType(GSYVideoType.SCREEN_MATCH_FULL); 

 //4:3
GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_4_3); 
//切换渲染
//默认TextureView
GSYVideoType.setRenderType(GSYVideoType.TEXTURE);

//SurfaceView,动画切换等时候效果比较差
GSYVideoType.setRenderType(GSYVideoType.SUFRACE);

//GLSurfaceView、支持滤镜
GSYVideoType.setRenderType(GSYVideoType.GLSURFACE);

 

posted @ 2021-04-21 17:09  码弄  阅读(892)  评论(0编辑  收藏  举报