赞
踩
npm i hls.js@1.0.9-0.canary.7938
import Hls from "hls.js"
mounted() {
const that= this
this.hls = new Hls()
const video = this.$refs.video_player
this.hls.attachMedia(video)
this.hls.on(Hls.Events.MEDIA_ATTACHED, () => {
that.hls.loadSource(that.videoUrl)
})
this.hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
video.play()
});
},
<template> <div class="container"> <video autoplay muted controls width="500" height="400" ref="video_player"></video> </div> </template> <script lang="ts"> import {defineComponent, ref} from 'vue'; import Hls from "hls.js"; /** * 组件名称: * 组件描述: */ export default defineComponent({ name: 'HLSVideoPlayer', components: {}, props: { videoUrl: { type: String, default: 'http://xxx.m3u8 } }, setup() { return { hls: ref(undefined), }; }, watch: { videoUrl() { this.hls.loadSource(this.videoUrl) } }, mounted() { const that= this this.hls = new Hls() const video = this.$refs.video_player this.hls.attachMedia(video) this.hls.on(Hls.Events.MEDIA_ATTACHED, () => { that.hls.loadSource(that.videoUrl) }) this.hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) { video.play() }); }, }); </script> <style scoped lang="scss"> </style>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。