TcPlayer.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div
  3. class="player"
  4. :style="'width:100%' + 'height:100%'">
  5. <div class="video" id="tcplayer" ref="tcplayer"></div>
  6. </div>
  7. </template>
  8. <script>
  9. import { TcPlayer } from '@/api/components/tcplayer'
  10. export default {
  11. name: 'TcPlayer',
  12. components: {},
  13. props: {
  14. widthHeigt: {
  15. type: Array,
  16. default: () => {
  17. return [300, 100]
  18. }
  19. },
  20. playVideo: ''
  21. },
  22. watch: {
  23. playVideo: function(newVal) {
  24. this.play()
  25. }
  26. },
  27. methods: {
  28. play() {
  29. if(this.playVideo==''||this.playVideo==null){
  30. return
  31. }
  32. let dom = document.getElementById('tcplayer')
  33. // let dom = this.$refs.tcplayer;
  34. // console.log(dom);
  35. while (dom.hasChildNodes()) {
  36. //当div下还存在子节点时 循环继续
  37. dom.removeChild(dom.firstChild)
  38. // this.player.destroy();
  39. }
  40. // console.log(JSON.stringify(this.playVideo));
  41. let objectString = JSON.stringify(this.playVideo)
  42. if (objectString != '{}') {
  43. this.player = new TcPlayer('tcplayer', {
  44. m3u8: '',
  45. m3u8_sd: this.playVideo, //请替换成实际可用的播放地址
  46. m3u8_hd: '',
  47. // flv_sd: this.playVideo.flv_sd, //请替换成实际可用的播放地址
  48. // flv_hd: this.playVideo.flv_hd, //请替换成实际可用的播放地址
  49. autoplay: true, //iOS 下 safari 浏览器,以及大部分移动端浏览器是不开放视频自动播放这个能力的
  50. // poster: "http://www.test.com/myimage.jpg",
  51. flash: false,
  52. h5_flv: true,
  53. width: this.widthHeigt[0] + '%', //视频的显示宽度,请尽量使用视频分辨率宽度
  54. height: this.widthHeigt[1] + '%', //视频的显示高度,请尽量使用视频分辨率高度
  55. live: true,
  56. volume: 0,
  57. clarity: 'sd',
  58. wording: {
  59. 2: '摄像头连接网络不稳定',
  60. 1002: '摄像头连接网络不稳定,请切换清晰度'
  61. }
  62. })
  63. }
  64. },
  65. destroyed() {
  66. // 页面销毁,同时也销毁 TcPlayer
  67. this.player.destroy()
  68. }
  69. }
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. .player {
  74. width: 100%;
  75. height: 100%;
  76. ::v-deep .video {
  77. width: 100%;
  78. height: 100%;
  79. .vcp-player {
  80. width: 100%;
  81. height: 100%;
  82. video {
  83. width: 100%;
  84. height: 100%;
  85. object-fit: fill;
  86. }
  87. }
  88. }
  89. }
  90. </style>