我是靠谱客的博主 故意小懒虫,这篇文章主要介绍vue中使用videojs播放m3u8格式的视频,现在分享给大家,希望可以做个参考。

1.安装videojs

复制代码
1
2
npm install --save video.js

2.使用

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<template> <div class="video-box"> <video id="video" class="video-js vjs-default-skin vjs-big-play-centered" controls preload="none" ></video> </div> </template> <script> import videojs from "video.js"; import 'video.js/dist/video-js.css' // 播放器样式,不引入播放器样式贼乱了 export default { props: { videoUrl: { type: String, required: true, }, }, data() { return { // videoUrl: 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8' myPlayer: null, }; }, mounted() { // 动态加载video,关闭时卸载,否则只能播放第一个视频 this.$nextTick(() => { if (this.myPlayer) { this.myPlayer.dispose(); $(".video-box").html( '<video id="video" class="video-js vjs-default-skin" controls width="500" height="264"></video>' ); } else { this.getVideo(); this.myPlayer.dispose(); $(".video-box").html( '<video id="video" class="video-js vjs-default-skin" controls width="500" height="264"></video>' ); } this.getVideo() }); }, methods: { getVideo() { this.myPlayer = videojs( "video", { //确定播放器是否具有用户可以与之交互的控件。没有控件,启动视频播放的唯一方法是使用autoplay属性或通过Player API。 controls: true, //自动播放属性,muted:静音播放 muted: true, autoplay: true, //建议浏览器是否应在<video>加载元素后立即开始下载视频数据。 preload: "auto", //设置视频播放器的显示宽度(以像素为单位) // width: "400px", //设置视频播放器的显示高度(以像素为单位) // height: "522px", // url // poster: 'https://static.shuxuejia.com/img/video_image.png', sources: [ { src: this.videoUrl, type: "application/x-mpegURL", }, ], playbackRates: [0.5, 1, 1.5, 2], //倍速播放 }, function onPlayerReady() { videojs.log("Your player is ready!"); // 比如: 播放量+1请求 this.on("ended", function () { videojs.log("Awww...over so soon?!"); }); } ); } } } </script>

最后

以上就是故意小懒虫最近收集整理的关于vue中使用videojs播放m3u8格式的视频的全部内容,更多相关vue中使用videojs播放m3u8格式内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(69)

评论列表共有 0 条评论

立即
投稿
返回
顶部