<template>
<div class="video-container">
<video ref="videoPlayer" class="video-js">
</video>
</div>
</template>
<script setup>
import { nextTick, onMounted, onUnmounted, ref, watch, watchEffect } from "vue"
import videojs from "video.js"
import "video.js/dist/video-js.css"
const props = defineProps({
videoUrl: { type: String, default: '' },
})
const videoPlayer = ref(null)
let myPlayer = null
const options = ref({
// poster: "//vjs.zencdn.net/v/oceans.png",
controls: true,
sources: [
{
src: props.videoUrl,
// type: 'video/mp4',
type: 'application/x-mpegURL',
}
],
controlBar: {
remainingTimeDisplay: {
displayNegative: false
}
},
playbackRates: [0.5, 1, 1.5, 2],
autoplay: "muted",
// autoDisable: true,
controls: false
})
onMounted(() => {
myPlayer = videojs(videoPlayer.value, options.value, () => {
myPlayer.log("play.....")
})
myPlayer.src(props.videoUrl);
myPlayer.load()
})
watch(
() => props.videoUrl,
(val, oldVal) => {
myPlayer = videojs(videoPlayer.value, options.value, () => {
myPlayer.log("play.....")
})
myPlayer.src(val);
myPlayer.load()
}
)
onUnmounted(() => {
if (myPlayer) {
myPlayer.dispose()
}
})
</script>
<style lang="scss" scoped>
.video-container {
width: 100%;
height: 100%;
.video-js {
width: 100%;
height: 100%;
}
}
</style>
videojs播放hls流
最新推荐文章于 2025-03-25 09:11:25 发布