这里是Vue结合Video.js播放m3u8视频流的完整攻略:
这里是Vue结合Video.js播放m3u8视频流的完整攻略:
一、安装Video.js
使用npm安装Video.js:
npm install video.js --save
二、引入Video.js和CSS文件
在Vue的App.vue中引入Video.js和CSS文件:
<template>
<div>
<video
id="myPlayer"
class="video-js vjs-default-skin vjs-big-play-centered"
controls
preload="auto"
width="640"
height="264"
>
<source :src="sourceUrl" type="application/x-mpegURL" />
</video>
</div>
</template>
<script>
import videojs from "video.js";
import "video.js/dist/video-js.css";
export default {
name: "App",
data() {
return {
sourceUrl: "http://example.com/example.m3u8",
};
},
mounted() {
this.player = videojs("myPlayer", {
fluid: true,
autoplay: true,
});
},
destroyed() {
if (this.player) {
this.player.dispose();
}
},
};
</script>
三、使用Video.js播放m3u8视频流
以上代码创建了一个Video.js播放器,这里设置了视频源的URL为http://example.com/example.m3u8。
四、动态改变视频源
<template>
<div>
<video
id="myPlayer"
class="video-js vjs-default-skin vjs-big-play-centered"
controls
preload="auto"
width="640"
height="264"
>
<source :src="sourceUrl" type="application/x-mpegURL" />
</video>
<button @click="changeVideoSource">change video source</button>
</div>
</template>
<script>
import videojs from "video.js";
import "video.js/dist/video-js.css";
export default {
name: "App",
data() {
return {
sourceUrl: "http://example.com/example.m3u8",
};
},
mounted() {
this.player = videojs("myPlayer", {
fluid: true,
autoplay: true,
});
},
destroyed() {
if (this.player) {
this.player.dispose();
}
},
methods: {
changeVideoSource() {
this.sourceUrl = "http://example.com/new_example.m3u8";
this.player.src(this.sourceUrl);
},
},
};
</script>
以上代码添加了一个按钮,当点击按钮时,会动态修改视频源的URL。在Vue中,使用:src绑定视频源,通过修改数据绑定的sourceUrl属性来动态改变视频源。同时,在changeVideoSource方法中,使用player.src方法将新的URL设置为视频的源。
编程基础网
本文标题为:Vue结合Video.js播放m3u8视频流的方法示例
基础教程推荐
猜你喜欢
- 基于Jquery ajax技术实现间隔N秒向某页面传值 2022-10-17
- AJAX分页效果简单实现 2023-02-13
- vue文章下载功能实现 2023-10-08
- 深入解析CSS的Sass框架中混合宏的使用 2023-12-08
- 浅谈Ajax和JavaScript的区别 2023-01-20
- javascript中关于&& 和 || 表达式的小技巧分享 2023-12-01
- HTML中的表单Form实现居中效果 2022-09-20
- Ajax跨域问题及解决方案(jsonp,cors) 2023-02-22
- 编写轻量ajax组件01-与webform平台上的各种实现方式比较 2022-10-17
- 第19天 django 文件上传 CBV和FBV html模板语言 url的正则表达式 django的路由名称 django使用mysql注意的事项 model的CRUD django的字段参数 d 2023-10-25
