| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <script>
- import Player from "@/utils/Player";
- // import {WebViewBridge} from "@polyv/web-view-bridge";
- export default {
- name: "SmallVideo",
- data() {
- return {
- playerInstance: null,
- width: 0,
- height: 0,
- showSmallWindow: false,
- webviewBridge: null,
- }
- },
- mounted() {
- this.handleInitPlayer();
- },
- methods: {
- // 初始化播放器
- handleInitPlayer() {
- this.playerInstance = new Player();
- this.$nextTick(async () => {
- await this.playerInstance.loadPlayerScript();
- this.playerInstance.loadPlayer();
- setTimeout(() => {
- this.playerInstance.play();
- }, 1000)
- })
- const smallVideo = document.querySelector(".small-video");
- this.width = smallVideo.clientWidth;
- this.height = smallVideo.clientHeight;
- console.log("playerInstance", this.playerInstance)
- // this.webviewBridge = new WebViewBridge();
- },
- // 进入小窗
- handleSmallWindow() {
- this.showSmallWindow = true;
- this.$nextTick(() => {
- this.handleInitPlayer();
- this.webviewBridge?.sendData('clickProduct', {
- newPage: false,
- ...{width: 375, height: 180,}
- });
- })
- },
- // 退出小窗
- handleExitSmallWindow() {
- this.webviewBridge?.sendData('changeToNormal', {});
- this.showSmallWindow = false;
- this.$emit("exit");
- },
- }
- }
- </script>
- <template>
- <div class="small-video" v-show="showSmallWindow">
- <div class="video-container"
- :style="{'--width': width + 'px', '--height': height + 'px'}"
- :id="playerInstance?.playerId"></div>
- <!-- <div class="close-btn" @click="handleExitSmallWindow">关闭小窗</div>-->
- </div>
- </template>
- <style scoped>
- .small-video {
- width: 100%;
- height: 180px;
- position: fixed;
- left: 0;
- top: 0;
- z-index: 9999;
- }
- .video-container {
- width: 100%;
- height: 100%;
- }
- /deep/ .plv-player-container {
- width: var(--width);
- height: var(--height);
- }
- .close-btn {
- position: absolute;
- right: 0;
- top: 0;
- z-index: 9999;
- box-sizing: border-box;
- padding: 8px 12px;
- border-radius: 8px;
- color: #FFFFFF;
- background: #000000;
- }
- </style>
|