checkVideo.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <el-dialog
  3. :title="dialogTitle"
  4. v-model="dialogVisible"
  5. width="600px"
  6. @close="closeDialog(0)"
  7. @open="open"
  8. >
  9. <div
  10. v-html="randerHtml"
  11. style="width: 100%; height: 400px; background: #000"
  12. ></div>
  13. </el-dialog>
  14. </template>
  15. <script>
  16. import { defineComponent, ref, watchEffect } from 'vue'
  17. import videojs from 'video.js'
  18. import 'videojs-contrib-hls'
  19. export default defineComponent({
  20. name: 'CheckVideo',
  21. emits: ['closeDialog'],
  22. props: {
  23. flag: Boolean,
  24. dialogTitle: String,
  25. itemInfo: Object,
  26. deviceCode: String,
  27. },
  28. setup(props, context) {
  29. context
  30. const dialogVisible = ref(false)
  31. const videoUrl = ref('')
  32. const options = []
  33. const player = ref('')
  34. const randerHtml = ref('')
  35. // open(): Dialog弹窗打开之前做的事
  36. const open = () => {
  37. videoUrl.value = 'http://47.103.74.123/hls/'+props.deviceCode+'.m3u8';
  38. // alert(videoUrl.value)
  39. // videoUrl.value ='http://cctvalih5ca.v.myalicdn.com/live/cctv1_2/index.m3u8'
  40. window.setTimeout(getVideo, 100)
  41. }
  42. function getVideo() {
  43. randerHtml.value =
  44. '<video id="my-video" class="video-js vjs-default-skin" controls preload="auto" style="width: 100%; height: 400px" poster loop="loop" autoplay="autoplay" ></video>'
  45. let options = {
  46. bigPlayButton: false,
  47. textTrackDisplay: false,
  48. posterImage: true,
  49. errorDisplay: false,
  50. controlBar: true,
  51. autoplay: true,
  52. controls: true,
  53. sources: [
  54. {
  55. src: videoUrl.value,
  56. type: 'application/x-mpegURL',
  57. },
  58. ],
  59. }
  60. window.setTimeout(function () {
  61. player.value = videojs('my-video', options,)
  62. }, 100)
  63. }
  64. // 关闭弹框
  65. const closeDialog = () => {
  66. if (player.value) {
  67. player.value.dispose()
  68. randerHtml.value = ''
  69. }
  70. context.emit('closeDialog', false)
  71. dialogVisible.value = false
  72. }
  73. watchEffect((fn, options) => {
  74. fn, options
  75. dialogVisible.value = props.flag
  76. })
  77. return {
  78. closeDialog,
  79. dialogVisible,
  80. options,
  81. open,
  82. videoUrl,
  83. getVideo,
  84. player,
  85. randerHtml,
  86. }
  87. },
  88. })
  89. </script>
  90. <style scoped lang="scss">
  91. .el-input,
  92. .el-select {
  93. width: 240px;
  94. }
  95. // label样式
  96. .el-form-item__label {
  97. width: 150px
  98. }
  99. .el-form-item__content {
  100. margin-left: 150px
  101. }
  102. </style>
  103. <style >
  104. * { touch-action: pan-y; }
  105. </style>