|
|
@@ -1,8 +1,9 @@
|
|
|
<template>
|
|
|
<div :class="{'full': full}" @click="handleChangeControl">
|
|
|
- <div id="player"></div>
|
|
|
- <div class="test">测试内容</div>
|
|
|
- <full-control v-model="showControl" @exit="handleExitFullScreen" v-if="false" />
|
|
|
+ <div :id="playerInstance.playerId" class="player"></div>
|
|
|
+ <div class="control">
|
|
|
+ <full-control v-model="showControl" @exit="handleExitFullScreen" :playerInstance="playerInstance" />
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
@@ -19,44 +20,27 @@ export default {
|
|
|
visible: {
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
+ },
|
|
|
+ playerInstance: {
|
|
|
+ type: Object,
|
|
|
+ default: () => {
|
|
|
+ return {}
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
- vodPlayerJs: 'https://player.polyv.net/resp/vod-player/latest/player.js',
|
|
|
- vid:'88083abbf5bcf1356e05d39666be527a_8',
|
|
|
- full: true,
|
|
|
+ full: false,
|
|
|
showControl: false,
|
|
|
- player: null,
|
|
|
};
|
|
|
},
|
|
|
mounted(){
|
|
|
- this.loadPlayerScript(this.loadPlayer);
|
|
|
- this.registerEvent();
|
|
|
+ this.$nextTick( async() => {
|
|
|
+ await this.playerInstance.loadPlayerScript();
|
|
|
+ this.playerInstance.loadPlayer();
|
|
|
+ })
|
|
|
},
|
|
|
methods: {
|
|
|
- // 注册事件
|
|
|
- registerEvent() {
|
|
|
- // 切换清晰度
|
|
|
- this.$bus.$on('switchBitrate', (number) => {
|
|
|
- this.player.switchBitrate(number);
|
|
|
- console.log("切换清晰度", number)
|
|
|
- })
|
|
|
-
|
|
|
- // 跳转时刻
|
|
|
- this.$bus.$on("seek_video", this.handleSeekTo);
|
|
|
-
|
|
|
- // 暂停播放
|
|
|
- this.$bus.$on("c_player_pause", () => {
|
|
|
- this.player.j2s_pauseVideo();
|
|
|
- })
|
|
|
-
|
|
|
- // 播放
|
|
|
- this.$bus.$on("c_player_play", () => {
|
|
|
- this.player.j2s_resumeVideo();
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
// 退出全屏
|
|
|
handleExitFullScreen() {
|
|
|
this.full = false;
|
|
|
@@ -70,73 +54,6 @@ export default {
|
|
|
this.showControl = !this.showControl;
|
|
|
|
|
|
},
|
|
|
-
|
|
|
- // 跳转某个时刻播放(秒)
|
|
|
- handleSeekTo(number) {
|
|
|
- this.player.j2s_seekVideo(number);
|
|
|
- },
|
|
|
-
|
|
|
- loadPlayerScript(callback) {
|
|
|
- if (!window.polyvPlayer) {
|
|
|
- const myScript = document.createElement('script');
|
|
|
- myScript.setAttribute('src', this.vodPlayerJs);
|
|
|
- myScript.onload = callback;
|
|
|
- document.body.appendChild(myScript);
|
|
|
- } else {
|
|
|
- callback();
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- loadPlayer() {
|
|
|
- const polyvPlayer = window.polyvPlayer;
|
|
|
- this.player = polyvPlayer({
|
|
|
- wrap: '#player',
|
|
|
- vid: this.vid ,
|
|
|
- skinLocation: 0,
|
|
|
- autoplay: true,
|
|
|
- df: 3
|
|
|
- });
|
|
|
- this.initPlayer();
|
|
|
- },
|
|
|
-
|
|
|
- // 初始化完成监听
|
|
|
- initPlayer() {
|
|
|
- this.player.on('s2j_onPlayerInitOver',() => {
|
|
|
- // 获取视频总时长
|
|
|
- const totalTime = this.player.j2s_getDuration();
|
|
|
- this.$bus.$emit("player_init_over", totalTime);
|
|
|
- });
|
|
|
-
|
|
|
- //初次播放触发
|
|
|
- this.player.on("s2j_onPlayStart", () => {
|
|
|
- this.$bus.$emit("player_play_start");
|
|
|
- })
|
|
|
-
|
|
|
- // 开始播放
|
|
|
- this.player.on("s2j_onVideoPlay", () => {
|
|
|
- const currentTime = this.player.j2s_getCurrentTime();
|
|
|
- this.$bus.$emit("player_play", currentTime);
|
|
|
- })
|
|
|
-
|
|
|
- // 暂停播放
|
|
|
- this.player.on("s2j_onVideoPause", () => {
|
|
|
- this.$bus.$emit("player_pause");
|
|
|
- })
|
|
|
-
|
|
|
- // 拖拽监听
|
|
|
- this.player.on("s2j_onVideoSeek", () => {
|
|
|
- const currentTime = this.player.j2s_getCurrentTime();
|
|
|
- this.$bus.$emit("player_drag_seek", currentTime);
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
- // 卸载
|
|
|
- destroyPlayer() {
|
|
|
- if (this.player) {
|
|
|
- this.player.destroy();
|
|
|
- this.player = null;
|
|
|
- }
|
|
|
- }
|
|
|
},
|
|
|
watch: {
|
|
|
visible(val) {
|
|
|
@@ -146,25 +63,14 @@ export default {
|
|
|
this.$emit("change", val);
|
|
|
}
|
|
|
},
|
|
|
- destroyed() {
|
|
|
- this.destroyPlayer();
|
|
|
- }
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.full {
|
|
|
- //width: 100vh;
|
|
|
- //height: 100vw;
|
|
|
- //position: fixed;
|
|
|
- //top: calc(50% - 50vw);
|
|
|
- //left: calc(50% - 50vh);
|
|
|
+ /*开了后定位会失效*/
|
|
|
//transition: transform 0.3s ease-in-out;
|
|
|
- //transform: rotate(90deg);
|
|
|
- //z-index: 99;
|
|
|
- //background: #000000;
|
|
|
- background: pink;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -177,29 +83,28 @@ export default {
|
|
|
height: 100vw;
|
|
|
}
|
|
|
|
|
|
-.full #player {
|
|
|
- //position: fixed;
|
|
|
- //z-index: 1;
|
|
|
-
|
|
|
+.player {
|
|
|
width: 100vh;
|
|
|
height: 100vw;
|
|
|
- position: fixed;
|
|
|
+ position: absolute;
|
|
|
top: calc(50% - 50vw);
|
|
|
left: calc(50% - 50vh);
|
|
|
- transition: transform 0.3s ease-in-out;
|
|
|
- transform: rotate(90deg);
|
|
|
z-index: 9;
|
|
|
background: #000000;
|
|
|
}
|
|
|
|
|
|
-.test {
|
|
|
- color: #FFFFFF;
|
|
|
- position: fixed;
|
|
|
- top: 50%;
|
|
|
- left: 0;
|
|
|
- background: pink;
|
|
|
- width: 100%;
|
|
|
+.full .control {
|
|
|
+ width: 100vh;
|
|
|
+ height: 100vw;
|
|
|
+ position: absolute;
|
|
|
+ top: calc(50% - 50vw);
|
|
|
+ left: calc(50% - 50vh);
|
|
|
+ transform: rotate(90deg);
|
|
|
z-index: 99999;
|
|
|
}
|
|
|
|
|
|
+.full .player {
|
|
|
+ transform: rotate(90deg);
|
|
|
+}
|
|
|
+
|
|
|
</style>
|