|
|
@@ -32,6 +32,10 @@ const props = defineProps({
|
|
|
height: {
|
|
|
type: String,
|
|
|
default: '630px'
|
|
|
+ },
|
|
|
+ uid: {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
}
|
|
|
})
|
|
|
const playing = ref(false)
|
|
|
@@ -50,11 +54,27 @@ const config = reactive({
|
|
|
WCS: true
|
|
|
})
|
|
|
|
|
|
-const playCreate = () => {
|
|
|
+// 动态加载 EasyPlayer
|
|
|
+function loadEasyPlayer() {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ if (window.EasyPlayerPro) {
|
|
|
+ resolve(window.EasyPlayerPro)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const script = document.createElement('script')
|
|
|
+ script.src = '/js/EasyPlayer/EasyPlayer-pro.js'
|
|
|
+ script.onload = () => resolve(window.EasyPlayerPro)
|
|
|
+ script.onerror = reject
|
|
|
+ document.head.appendChild(script)
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+const playCreate = async () => {
|
|
|
const container = easyPlayerRef.value
|
|
|
if (!container) return
|
|
|
|
|
|
- const uid = route.params._uid || Date.now() // 使用时间戳作为唯一标识
|
|
|
+ const uid = props.uid || route.params._uid || Date.now() // 使用时间戳作为唯一标识
|
|
|
|
|
|
easyplayer[uid] = new EasyPlayerPro(container, {
|
|
|
isLive: config.isLive,
|
|
|
@@ -106,8 +126,9 @@ const playCreate = () => {
|
|
|
}
|
|
|
|
|
|
// 播放视频
|
|
|
-function play(url) {
|
|
|
- const uid = route.params._uid || Date.now()
|
|
|
+async function play(url) {
|
|
|
+ await loadEasyPlayer()
|
|
|
+ const uid = props.uid || route.params._uid || Date.now() // 使用时间戳作为唯一标识
|
|
|
|
|
|
// 确保容器已准备就绪
|
|
|
if (!easyPlayerRef.value) {
|
|
|
@@ -141,7 +162,7 @@ function play(url) {
|
|
|
}
|
|
|
|
|
|
const pause = () => {
|
|
|
- const uid = route.params._uid || Date.now()
|
|
|
+ const uid = props.uid || route.params._uid || Date.now() // 使用时间戳作为唯一标识
|
|
|
|
|
|
if (easyplayer[uid]) {
|
|
|
easyplayer[uid].pause()
|
|
|
@@ -151,7 +172,7 @@ const pause = () => {
|
|
|
|
|
|
// 截图
|
|
|
const screenshot = () => {
|
|
|
- const uid = route.params._uid || Date.now()
|
|
|
+ const uid = props.uid || route.params._uid || Date.now() // 使用时间戳作为唯一标识
|
|
|
|
|
|
if (easyplayer[uid]) {
|
|
|
easyplayer[uid].screenshot()
|
|
|
@@ -160,7 +181,7 @@ const screenshot = () => {
|
|
|
}
|
|
|
|
|
|
const destroy = async () => {
|
|
|
- const uid = route.params._uid || Date.now()
|
|
|
+ const uid = props.uid || route.params._uid || Date.now() // 使用时间戳作为唯一标识
|
|
|
|
|
|
if (easyplayer[uid]) {
|
|
|
await easyplayer[uid].destroy().then(() => {
|
|
|
@@ -183,7 +204,7 @@ const onMute = () => {
|
|
|
// playInfo.value.setMute(true)
|
|
|
// }
|
|
|
|
|
|
- const uid = route.params._uid || Date.now()
|
|
|
+ const uid = props.uid || route.params._uid || Date.now() // 使用时间戳作为唯一标识
|
|
|
|
|
|
if (easyplayer[uid]) {
|
|
|
easyplayer[uid].setMute(true)
|
|
|
@@ -285,8 +306,8 @@ onMounted(() => {
|
|
|
})
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
- if (easyplayer[route.params._uid]) {
|
|
|
- easyplayer[route.params._uid].destroy()
|
|
|
+ if (easyplayer[props.uid || route.params._uid || Date.now()]) {
|
|
|
+ easyplayer[props.uid || route.params._uid || Date.now()].destroy()
|
|
|
}
|
|
|
playing.value = false
|
|
|
})
|