赞
踩
GSYVideoPlayer 可以播放rtsp 但是看Github 没有找到具体怎么配置播放的。
GSYVideoPlayer:https://github.com/CarGuo/GSYVideoPlayer
这里总结下
1、导入依赖包
- //基础包
- implementation 'com.shuyu:gsyVideoPlayer-java:7.1.4'
- //是否需要ExoPlayer模式
- implementation 'com.shuyu:GSYVideoPlayer-exo2:7.1.4'
- //更多ijk的编码支持
- implementation 'com.shuyu:gsyVideoPlayer-ex_so:7.1.4'
其中 gsyVideoPlayer-ex_so 是播放 rtsp的。一定得有才行。不让会报错 Protocol not found 等。
2、 xml中主要播放控件
- <com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
- android:id="@+id/videoPlayer"
- android:layout_width="match_parent"
- android:layout_height="250dp"
- android:src="@drawable/meinv" />
activity中播放设置
- @BindView(R.id.videoPlayer)
- StandardGSYVideoPlayer videoPlayer;
- OrientationUtils orientationUtils;
-
- private void startVideo() {
- videoPlayer.setUp(url, true, "测试视频");
- VideoOptionModel videoOptionModel = new
- VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "rtsp_transport", "tcp");
- List<VideoOptionModel> list = new ArrayList<>();
- list.add(videoOptionModel);
- videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "rtsp_flags", "prefer_tcp");
- list.add(videoOptionModel);
- videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT,
- "allowed_media_types", "video"); //根据媒体类型来配置
- list.add(videoOptionModel);
- videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", 20000);
- list.add(videoOptionModel);
- videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "buffer_size", 1316);
- list.add(videoOptionModel);
- videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "infbuf", 1); // 无限读
- list.add(videoOptionModel);
- videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzemaxduration", 100);
- list.add(videoOptionModel);
- videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "probesize", 10240);
- list.add(videoOptionModel);
- videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "flush_packets", 1);
- list.add(videoOptionModel);
- // 关闭播放器缓冲,这个必须关闭,否则会出现播放一段时间后,一直卡主,控制台打印 FFP_MSG_BUFFERING_START
- videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", 0);
- list.add(videoOptionModel);
- GSYVideoManager.instance().setOptionModelList(list);
- //增加封面
- ImageView imageView = new ImageView(this);
- imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
- imageView.setImageResource(R.mipmap.tz_picture_load_false);
- videoPlayer.setThumbImageView(imageView);
- //增加title
- videoPlayer.getTitleTextView().setVisibility(View.VISIBLE);
- //设置返回键
- videoPlayer.getBackButton().setVisibility(View.VISIBLE);
- //设置旋转
- orientationUtils = new OrientationUtils(this, videoPlayer);
- //设置全屏按键功能,这是使用的是选择屏幕,而不是全屏
- videoPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- orientationUtils.resolveByClick();
- }
- });
- //是否可以滑动调整
- videoPlayer.setIsTouchWiget(true);
- //设置返回按键功能
- videoPlayer.getBackButton().setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- onBackPressed();
- }
- });
- videoPlayer.startPlayLogic();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- videoPlayer.onVideoPause();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- videoPlayer.onVideoResume();
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- GSYVideoManager.releaseAllVideos();
- if (orientationUtils != null)
- orientationUtils.releaseListener();
- }
-
- @Override
- public void onBackPressed() {
- //先返回正常状态
- if (orientationUtils.getScreenType() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
- videoPlayer.getFullscreenButton().performClick();
- return;
- }
- //释放所有
- videoPlayer.setVideoAllCallBack(null);
- super.onBackPressed();
- }
OK,这样就可以播放了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。