playVideo.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div :id="'video-box' + _uid" class="video">
  3. <div :id="'ezuikit-player' + _uid"></div>
  4. </div>
  5. </template>
  6. <script>
  7. // import EZUIKit from 'ezuikit-js';
  8. import {
  9. getCameraAccessToken
  10. } from '@/httpApi/iot'
  11. export default {
  12. props: {
  13. sourceUrl: {
  14. type: String,
  15. default: ''
  16. },
  17. template: {
  18. type: String,
  19. default: 'simple'
  20. },
  21. time: {
  22. type: Number,
  23. default: 1
  24. }
  25. },
  26. data() {
  27. return {
  28. player: null,
  29. width: 352,
  30. height: 198,
  31. reset: 0
  32. };
  33. },
  34. computed: {},
  35. mounted() {
  36. // let _self = this;
  37. // _self.$nextTick(() => {
  38. // this.width = document.getElementById('video-box' + this._uid).clientWidth;
  39. // this.height = document.getElementById('video-box' + this._uid).clientHeight;
  40. // if (this.sourceUrl) setTimeout(() => {
  41. // this.init();
  42. // }, 2000 * this.time);
  43. // });
  44. },
  45. beforeDestroy() {
  46. if (this.player) this.destroy() //销毁并停止直播视频
  47. },
  48. methods: {
  49. init() {
  50. if (this.player) {
  51. this.destroy();
  52. }
  53. getCameraAccessToken().then(res => {
  54. if (res.state) {
  55. this.player = new EZUIKit.EZUIKitPlayer({
  56. id: "ezuikit-player" + this._uid, // 视频容器ID
  57. accessToken: res.data,
  58. url: this.sourceUrl,
  59. template: this.template,
  60. width: this.width,
  61. height: this.height,
  62. handleSuccess: () => {
  63. this.reset = 0;
  64. },
  65. handleError: (data) => {
  66. if (data.msg == "该用户不拥有该设备") return;
  67. if (this.reset < 5) {
  68. this.play();
  69. this.reset++
  70. }
  71. },
  72. });
  73. }
  74. })
  75. },
  76. play() {
  77. var playPromise = this.player.play();
  78. playPromise.then((data) => {
  79. console.log("promise 获取 数据", data);
  80. });
  81. },
  82. stop() {
  83. var stopPromise = this.player.stop();
  84. stopPromise.then((data) => {
  85. console.log("promise 获取 数据", data);
  86. });
  87. },
  88. getOSDTime() {
  89. var getOSDTimePromise = this.player.getOSDTime();
  90. getOSDTimePromise.then((data) => {
  91. console.log("promise 获取 数据", data);
  92. });
  93. },
  94. capturePicture() {
  95. var capturePicturePromise = this.player.capturePicture(
  96. `${new Date().getTime()}`
  97. );
  98. capturePicturePromise.then((data) => {
  99. console.log("promise 获取 数据", data);
  100. });
  101. },
  102. openSound() {
  103. var openSoundPromise = this.player.openSound();
  104. openSoundPromise.then((data) => {
  105. console.log("promise 获取 数据", data);
  106. });
  107. },
  108. closeSound() {
  109. var openSoundPromise = this.player.closeSound();
  110. openSoundPromise.then((data) => {
  111. console.log("promise 获取 数据", data);
  112. });
  113. },
  114. startSave() {
  115. var startSavePromise = this.player.startSave(`${new Date().getTime()}`);
  116. startSavePromise.then((data) => {
  117. console.log("promise 获取 数据", data);
  118. });
  119. },
  120. stopSave() {
  121. var stopSavePromise = this.player.stopSave();
  122. stopSavePromise.then((data) => {
  123. console.log("promise 获取 数据", data);
  124. });
  125. },
  126. ezopenStartTalk() {
  127. this.player.startTalk();
  128. },
  129. ezopenStopTalk() {
  130. this.player.stopTalk();
  131. },
  132. fullScreen() {
  133. this.player.fullScreen();
  134. },
  135. destroy() {
  136. if (!this.player.destroy) return this.$emit('closeVideoModel');
  137. this.stop();
  138. var destroyPromise = this.player.destroy();
  139. destroyPromise.then((data) => {
  140. console.log('关闭流成功');
  141. this.$emit('closeVideoModel');
  142. });
  143. this.player = null;
  144. }
  145. }
  146. };
  147. </script>
  148. <style lang="scss">
  149. .video {
  150. width: 100%;
  151. height: 100%;
  152. .loading {
  153. display: none;
  154. }
  155. }
  156. #webpack-dev-server-client-overlay {
  157. display: none !important;
  158. }
  159. </style>