Skip to content

Commit 618c464

Browse files
Merge pull request #10 from gianantoniopini/bugfix/issue-9/image-of-previous-video-shown-on-switch-to-landscape
fix: image of previously loaded video is shown on switch to landscape
2 parents 2664ce1 + a008325 commit 618c464

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/components/VideoPlayer.vue

+21-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup>
2-
import { onMounted, ref } from 'vue'
2+
import { onMounted, onUnmounted, ref } from 'vue'
33
44
import shakaPlayerUi from 'shaka-player/dist/shaka-player.ui.js'
55
import 'shaka-player/dist/controls.css'
@@ -14,7 +14,8 @@ const emit = defineEmits(['statusChange'])
1414
const videoContainerElement = ref(null)
1515
const videoElement = ref(null)
1616
17-
const localPlayer = new shakaPlayerUi.Player()
17+
let uiOverlay = null
18+
let player = new shakaPlayerUi.Player()
1819
1920
const emitStatusChangeEvent = (status) => {
2021
emit('statusChange', status)
@@ -24,15 +25,15 @@ const initShakaPlayerUi = async () => {
2425
emitStatusChangeEvent('Initializing the Shaka Player UI. Please wait...')
2526
2627
try {
27-
const ui = new shakaPlayerUi.ui.Overlay(
28-
localPlayer,
28+
uiOverlay = new shakaPlayerUi.ui.Overlay(
29+
player,
2930
videoContainerElement.value,
3031
videoElement.value
3132
)
3233
33-
await localPlayer.attach(videoElement.value)
34+
await player.attach(videoElement.value)
3435
35-
ui.getControls()
36+
uiOverlay.getControls()
3637
3738
emitStatusChangeEvent('Shaka Player UI has been initialized.')
3839
} catch (error) {
@@ -45,7 +46,7 @@ const loadVideo = async () => {
4546
emitStatusChangeEvent(`Loading video ${props.manifestPath} . Please wait...`)
4647
4748
try {
48-
await localPlayer.load(props.manifestPath)
49+
await player.load(props.manifestPath)
4950
5051
emitStatusChangeEvent('')
5152
} catch (error) {
@@ -58,6 +59,19 @@ onMounted(async () => {
5859
await initShakaPlayerUi()
5960
await loadVideo()
6061
})
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+
})
6175
</script>
6276

6377
<template>

0 commit comments

Comments
 (0)