ffplayout/frontend/components/VideoPlayer.vue

78 lines
1.5 KiB
Vue
Raw Normal View History

2020-04-16 12:27:03 -04:00
<template>
<div>
<div v-if="options.sources">
<video
:id="reference"
class="video-js vjs-default-skin vjs-big-play-centered vjs-16-9"
width="1024"
height="576"
/>
</div>
</div>
</template>
2023-01-11 04:54:25 -05:00
<script setup lang="ts">
2020-04-16 12:27:03 -04:00
import videojs from 'video.js'
2022-12-20 04:04:45 -05:00
import 'video.js/dist/video-js.css'
2020-04-16 12:27:03 -04:00
2024-07-04 10:41:32 -04:00
const configStore = useConfig()
2023-01-11 04:54:25 -05:00
const player = ref()
2020-04-16 12:27:03 -04:00
2023-01-11 04:54:25 -05:00
const props = defineProps({
options: {
type: Object,
required: true,
2020-04-16 12:27:03 -04:00
},
2023-01-11 04:54:25 -05:00
reference: {
type: String,
required: true,
2020-04-16 12:27:03 -04:00
},
2023-01-11 04:54:25 -05:00
})
onMounted(() => {
2024-07-02 01:57:36 -04:00
const volume = localStorage.getItem('volume')
2023-01-11 04:54:25 -05:00
player.value = videojs(props.reference, props.options, function onPlayerReady() {
// console.log('onPlayerReady', this);
})
2024-07-02 01:57:36 -04:00
if (volume !== null) {
player.value.volume(volume)
}
player.value.on('volumechange', () => {
localStorage.setItem('volume', player.value.volume())
})
2024-07-04 10:41:32 -04:00
player.value.on('error', () => {
setTimeout(() => {
configStore.showPlayer = false
nextTick(() => {
configStore.showPlayer = true
})
}, 2000)
})
2023-01-11 04:54:25 -05:00
})
2020-04-16 12:27:03 -04:00
2023-01-11 04:54:25 -05:00
onBeforeUnmount(() => {
if (player.value) {
player.value.dispose()
2020-04-16 12:27:03 -04:00
}
2023-01-11 04:54:25 -05:00
})
2020-04-16 12:27:03 -04:00
</script>
2024-07-02 03:02:26 -04:00
<style>
.video-js .vjs-volume-panel.vjs-volume-panel-horizontal {
2024-07-04 10:41:32 -04:00
width: 10em;
2024-07-02 03:02:26 -04:00
}
.video-js .vjs-volume-panel .vjs-volume-control.vjs-volume-horizontal {
2024-07-04 10:41:32 -04:00
width: 5em;
height: 3em;
margin-right: 0;
opacity: 1;
2024-07-02 03:02:26 -04:00
}
</style>