1
1
<script setup>
2
- import { onMounted , ref } from ' vue'
2
+ import { onMounted , onUnmounted , ref } from ' vue'
3
3
4
4
import shakaPlayerUi from ' shaka-player/dist/shaka-player.ui.js'
5
5
import ' shaka-player/dist/controls.css'
@@ -14,7 +14,8 @@ const emit = defineEmits(['statusChange'])
14
14
const videoContainerElement = ref (null )
15
15
const videoElement = ref (null )
16
16
17
- const localPlayer = new shakaPlayerUi.Player ()
17
+ let uiOverlay = null
18
+ let player = new shakaPlayerUi.Player ()
18
19
19
20
const emitStatusChangeEvent = (status ) => {
20
21
emit (' statusChange' , status)
@@ -24,15 +25,15 @@ const initShakaPlayerUi = async () => {
24
25
emitStatusChangeEvent (' Initializing the Shaka Player UI. Please wait...' )
25
26
26
27
try {
27
- const ui = new shakaPlayerUi.ui.Overlay (
28
- localPlayer ,
28
+ uiOverlay = new shakaPlayerUi.ui.Overlay (
29
+ player ,
29
30
videoContainerElement .value ,
30
31
videoElement .value
31
32
)
32
33
33
- await localPlayer .attach (videoElement .value )
34
+ await player .attach (videoElement .value )
34
35
35
- ui .getControls ()
36
+ uiOverlay .getControls ()
36
37
37
38
emitStatusChangeEvent (' Shaka Player UI has been initialized.' )
38
39
} catch (error) {
@@ -45,7 +46,7 @@ const loadVideo = async () => {
45
46
emitStatusChangeEvent (` Loading video ${ props .manifestPath } . Please wait...` )
46
47
47
48
try {
48
- await localPlayer .load (props .manifestPath )
49
+ await player .load (props .manifestPath )
49
50
50
51
emitStatusChangeEvent (' ' )
51
52
} catch (error) {
@@ -58,6 +59,19 @@ onMounted(async () => {
58
59
await initShakaPlayerUi ()
59
60
await loadVideo ()
60
61
})
62
+
63
+ onUnmounted (async () => {
64
+ if (uiOverlay) {
65
+ await uiOverlay .destroy ()
66
+ }
67
+
68
+ if (player) {
69
+ await player .destroy ()
70
+ }
71
+
72
+ uiOverlay = undefined
73
+ player = undefined
74
+ })
61
75
</script >
62
76
63
77
<template >
0 commit comments