videoList.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div id="app">
  3. <div style="background-color: #FFFFFF; margin-bottom: 1rem; position: relative; padding: 0.5rem; text-align: left;">
  4. <span style="font-size: 1rem; font-weight: bold;">视频列表</span>
  5. <div style="position: absolute; right: 1rem; top: 0.3rem;">
  6. <el-button icon="el-icon-refresh-right" circle size="mini" @click="getVideoList()"></el-button>
  7. </div>
  8. </div>
  9. <div class="videoList">
  10. <div class="video-item" v-for="(item, index) in videoList">
  11. <video class="video-js vjs-default-skin vjs-big-play-centered" :id="genVideoId(index, item)" style="width: 15rem; height: 10rem;" controls>
  12. <!-- <source src="rtmp://218.59.173.214/rtp/0BEBC202" type="rtmp/flv"> -->
  13. </video>
  14. <div class="video-item-title">
  15. {{ item.stream }}
  16. <el-button icon="el-icon-search" circle size="mini" style="float: right;" @click="showVideoInfo(item)"></el-button>
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. import 'video.js/dist/video-js.css';
  24. import videojs from 'video.js';
  25. import 'videojs-flash';
  26. export default {
  27. name: 'app',
  28. components: {},
  29. data() {
  30. return {
  31. videoList: [],
  32. videoComponentList: []
  33. };
  34. },
  35. mounted() {
  36. this.getVideoList();
  37. },
  38. destroyed() {
  39. this.$destroy('videojs');
  40. //释放视频播放器空间
  41. this.videoList.forEach(item => {
  42. if(typeof item.video!='undefined'){
  43. item.video.dispose();
  44. }
  45. clearTimeout(item.delay);
  46. });
  47. },
  48. methods: {
  49. genVideoId: function(position, stream) {
  50. let that = this;
  51. var story_sources = [
  52. {
  53. type: 'rtmp/flv',
  54. src: that.$global.baseMediaUrl + stream.app + '/' + stream.stream
  55. }
  56. ];
  57. //延迟1s执行,给dom生成一定的时间
  58. stream.delay=setTimeout(function() {
  59. let player = videojs('video-' + position);
  60. player.ready(function() {
  61. var obj = this;
  62. obj.src(story_sources);
  63. stream.video=player;
  64. console.log(JSON.stringify(stream));
  65. });
  66. }, 1000);
  67. return 'video-' + position;
  68. },
  69. getVideoList: function() {
  70. let that = this;
  71. this.$axios({
  72. method: 'get',
  73. url: this.$global.genApiUrl('/getMediaList') + '&schema=rtmp'
  74. }).then(function(res) {
  75. console.log(JSON.stringify(res.data));
  76. if (res.data.code == 0) {
  77. that.videoList = res.data.data;
  78. }
  79. });
  80. },
  81. showVideoInfo: function(videoData) {
  82. let msg = '所属应用:' + videoData.app + ' 数据流类型:' + videoData.schema + ' 流名称:' + videoData.stream +' 观看人数:'+videoData.readerCount;
  83. this.$alert(msg, '视频信息', {
  84. confirmButtonText: '确定'
  85. });
  86. }
  87. }
  88. };
  89. </script>
  90. <style>
  91. .videoList {
  92. display: flex;
  93. flex-wrap: wrap;
  94. align-content: flex-start;
  95. }
  96. .video-item {
  97. width: 15rem;
  98. margin-right: 1rem;
  99. }
  100. .video-item-title {
  101. color: #000000;
  102. background-color: #ffffff;
  103. line-height: 1.5rem;
  104. padding: 0.3rem;
  105. }
  106. </style>