-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
video: add embedded video player & libraries
- Loading branch information
1 parent
c78cd8b
commit 77e2486
Showing
4 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<template> | ||
<div v-if="openDialog" class="modal"> | ||
<div class="overlay" @click="closeDialog"></div> | ||
<div class="modal-content"> | ||
<video-player | ||
class="video-player vjs-big-play-centered" | ||
:src="videoFile" | ||
poster="/images/poster/oceans.png" | ||
crossorigin="anonymous" | ||
playsinline | ||
controls | ||
:volume="0.6" | ||
:height="640" | ||
:playback-rates="[0.7, 1.0, 1.5, 2.0]" | ||
@mounted="handleMounted" | ||
@ready="handleEvent" | ||
@play="handleEvent" | ||
@pause="handleEvent" | ||
@ended="handleEvent" | ||
@loadeddata="handleEvent" | ||
@waiting="handleEvent" | ||
@playing="handleEvent" | ||
@canplay="handleEvent" | ||
@canplaythrough="handleEvent" | ||
@timeupdate="(event) => handleEvent(player?.currentTime())" | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import 'video.js/dist/video-js.css' | ||
import { VideoPlayer } from '@videojs-player/vue' | ||
import videojs from 'video.js' | ||
import { ref, shallowRef, watchEffect } from 'vue' | ||
type VideoJsPlayer = ReturnType<typeof videojs> | ||
const props = defineProps({ | ||
videoUrl: String, | ||
openVideoPlayerDialog: Boolean, | ||
}) | ||
const emit = defineEmits(['update:openVideoPlayerDialog']) | ||
const player = shallowRef<VideoJsPlayer | null>(null) | ||
const videoFile = ref(props.videoUrl) | ||
const openDialog = ref(props.openVideoPlayerDialog) | ||
const handleMounted = (payload: any): void => { | ||
player.value = payload.player | ||
console.log('Video player mounted', payload) | ||
} | ||
const handleEvent = (log: any): void => { | ||
console.log('Video player event', log) | ||
} | ||
const closeDialog = (): void => { | ||
emit('update:openVideoPlayerDialog', false) | ||
} | ||
watchEffect(() => { | ||
videoFile.value = props.videoUrl | ||
openDialog.value = props.openVideoPlayerDialog | ||
}) | ||
</script> | ||
|
||
<style scoped> | ||
.modal { | ||
position: fixed; | ||
top: 50%; | ||
left: 50%; | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
.overlay { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
} | ||
.modal-content { | ||
z-index: 10; | ||
position: relative; | ||
padding: 20px; | ||
background: white; | ||
border-radius: 8px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters