SmallVideo.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <script>
  2. import Player from "@/utils/Player";
  3. // import {WebViewBridge} from "@polyv/web-view-bridge";
  4. export default {
  5. name: "SmallVideo",
  6. data() {
  7. return {
  8. playerInstance: null,
  9. width: 0,
  10. height: 0,
  11. showSmallWindow: false,
  12. webviewBridge: null,
  13. }
  14. },
  15. mounted() {
  16. this.handleInitPlayer();
  17. },
  18. methods: {
  19. // 初始化播放器
  20. handleInitPlayer() {
  21. this.playerInstance = new Player();
  22. this.$nextTick(async () => {
  23. await this.playerInstance.loadPlayerScript();
  24. this.playerInstance.loadPlayer();
  25. setTimeout(() => {
  26. this.playerInstance.play();
  27. }, 1000)
  28. })
  29. const smallVideo = document.querySelector(".small-video");
  30. this.width = smallVideo.clientWidth;
  31. this.height = smallVideo.clientHeight;
  32. console.log("playerInstance", this.playerInstance)
  33. // this.webviewBridge = new WebViewBridge();
  34. },
  35. // 进入小窗
  36. handleSmallWindow() {
  37. this.showSmallWindow = true;
  38. this.$nextTick(() => {
  39. this.handleInitPlayer();
  40. this.webviewBridge?.sendData('clickProduct', {
  41. newPage: false,
  42. ...{width: 375, height: 180,}
  43. });
  44. })
  45. },
  46. // 退出小窗
  47. handleExitSmallWindow() {
  48. this.webviewBridge?.sendData('changeToNormal', {});
  49. this.showSmallWindow = false;
  50. this.$emit("exit");
  51. },
  52. }
  53. }
  54. </script>
  55. <template>
  56. <div class="small-video" v-show="showSmallWindow">
  57. <div class="video-container"
  58. :style="{'--width': width + 'px', '--height': height + 'px'}"
  59. :id="playerInstance?.playerId"></div>
  60. <!-- <div class="close-btn" @click="handleExitSmallWindow">关闭小窗</div>-->
  61. </div>
  62. </template>
  63. <style scoped>
  64. .small-video {
  65. width: 100%;
  66. height: 180px;
  67. position: fixed;
  68. left: 0;
  69. top: 0;
  70. z-index: 9999;
  71. }
  72. .video-container {
  73. width: 100%;
  74. height: 100%;
  75. }
  76. /deep/ .plv-player-container {
  77. width: var(--width);
  78. height: var(--height);
  79. }
  80. .close-btn {
  81. position: absolute;
  82. right: 0;
  83. top: 0;
  84. z-index: 9999;
  85. box-sizing: border-box;
  86. padding: 8px 12px;
  87. border-radius: 8px;
  88. color: #FFFFFF;
  89. background: #000000;
  90. }
  91. </style>