当前位置:   article > 正文

ijkplayer 播放rtsp GSYVideoPlayer播放rtsp rtsp Protocol not found

gsyvideoplayer播放rtsp

GSYVideoPlayer 可以播放rtsp 但是看Github 没有找到具体怎么配置播放的。
GSYVideoPlayer:https://github.com/CarGuo/GSYVideoPlayer
这里总结下

1、导入依赖包

  1. //基础包
  2. implementation 'com.shuyu:gsyVideoPlayer-java:7.1.4'
  3. //是否需要ExoPlayer模式
  4. implementation 'com.shuyu:GSYVideoPlayer-exo2:7.1.4'
  5. //更多ijk的编码支持
  6. implementation 'com.shuyu:gsyVideoPlayer-ex_so:7.1.4'

其中 gsyVideoPlayer-ex_so 是播放 rtsp的。一定得有才行。不让会报错  Protocol not found 等。

2、 xml中主要播放控件

  1. <com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
  2. android:id="@+id/videoPlayer"
  3. android:layout_width="match_parent"
  4. android:layout_height="250dp"
  5. android:src="@drawable/meinv" />

activity中播放设置

  1. @BindView(R.id.videoPlayer)
  2. StandardGSYVideoPlayer videoPlayer;
  3. OrientationUtils orientationUtils;
  4. private void startVideo() {
  5. videoPlayer.setUp(url, true, "测试视频");
  6. VideoOptionModel videoOptionModel = new
  7. VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "rtsp_transport", "tcp");
  8. List<VideoOptionModel> list = new ArrayList<>();
  9. list.add(videoOptionModel);
  10. videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "rtsp_flags", "prefer_tcp");
  11. list.add(videoOptionModel);
  12. videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT,
  13. "allowed_media_types", "video"); //根据媒体类型来配置
  14. list.add(videoOptionModel);
  15. videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", 20000);
  16. list.add(videoOptionModel);
  17. videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "buffer_size", 1316);
  18. list.add(videoOptionModel);
  19. videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "infbuf", 1); // 无限读
  20. list.add(videoOptionModel);
  21. videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzemaxduration", 100);
  22. list.add(videoOptionModel);
  23. videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "probesize", 10240);
  24. list.add(videoOptionModel);
  25. videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "flush_packets", 1);
  26. list.add(videoOptionModel);
  27. // 关闭播放器缓冲,这个必须关闭,否则会出现播放一段时间后,一直卡主,控制台打印 FFP_MSG_BUFFERING_START
  28. videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", 0);
  29. list.add(videoOptionModel);
  30. GSYVideoManager.instance().setOptionModelList(list);
  31. //增加封面
  32. ImageView imageView = new ImageView(this);
  33. imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
  34. imageView.setImageResource(R.mipmap.tz_picture_load_false);
  35. videoPlayer.setThumbImageView(imageView);
  36. //增加title
  37. videoPlayer.getTitleTextView().setVisibility(View.VISIBLE);
  38. //设置返回键
  39. videoPlayer.getBackButton().setVisibility(View.VISIBLE);
  40. //设置旋转
  41. orientationUtils = new OrientationUtils(this, videoPlayer);
  42. //设置全屏按键功能,这是使用的是选择屏幕,而不是全屏
  43. videoPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
  44. @Override
  45. public void onClick(View v) {
  46. orientationUtils.resolveByClick();
  47. }
  48. });
  49. //是否可以滑动调整
  50. videoPlayer.setIsTouchWiget(true);
  51. //设置返回按键功能
  52. videoPlayer.getBackButton().setOnClickListener(new View.OnClickListener() {
  53. @Override
  54. public void onClick(View v) {
  55. onBackPressed();
  56. }
  57. });
  58. videoPlayer.startPlayLogic();
  59. }
  60. @Override
  61. protected void onPause() {
  62. super.onPause();
  63. videoPlayer.onVideoPause();
  64. }
  65. @Override
  66. protected void onResume() {
  67. super.onResume();
  68. videoPlayer.onVideoResume();
  69. }
  70. @Override
  71. protected void onDestroy() {
  72. super.onDestroy();
  73. GSYVideoManager.releaseAllVideos();
  74. if (orientationUtils != null)
  75. orientationUtils.releaseListener();
  76. }
  77. @Override
  78. public void onBackPressed() {
  79. //先返回正常状态
  80. if (orientationUtils.getScreenType() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
  81. videoPlayer.getFullscreenButton().performClick();
  82. return;
  83. }
  84. //释放所有
  85. videoPlayer.setVideoAllCallBack(null);
  86. super.onBackPressed();
  87. }

OK,这样就可以播放了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/852609
推荐阅读
相关标签
  

闽ICP备14008679号