我是靠谱客的博主 追寻方盒,这篇文章主要介绍简单使用videojs 播放m3u8格式的视频,现在分享给大家,希望可以做个参考。

  1. 安装插件
复制代码
1
2
3
npm i videojs npm install --save video.jsnpm install --save video.js //窗口样式
  1. 局部引入
复制代码
1
2
3
4
import videojs from 'video.js' import 'video.js/dist/video-js.css' import 'videojs-contrib-hls'
  1. 使用
复制代码
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
<video id="videoPlayer" class="video-js"></video> // 配置 data: { return { options: { autoplay: true, // 设置自动播放 muted: true, // 设置了它为true,才可实现自动播放,同时视频也被静音(Chrome66及以上版本,禁止音视频的自动播放) preload: 'auto', // 预加载 controls: true // 显示播放的控件 }, player: null, } } // methods methods: { getVideo (nowPlayVideoUrl, index) { this.selectIndex = index this.player = videojs('videoPlayer', this.options) this.player.src([ { src: nowPlayVideoUrl.hlsStandard, // 地址 type: 'application/x-mpegURL' // 告诉videojs,这是一个hls流 } ]) }, } // 销毁 beforeDestroy () { if (this.player) { this.player.dispose() } }

// 官方例子

复制代码
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
<template> <div> <video ref="videoPlayer" class="video-js"></video> </div> </template> <script> import videojs from 'video.js'; export default { name: "VideoPlayer", props: { options: { type: Object, default() { return {}; } } }, data() { return { player: null } }, mounted() { this.player = videojs(this.$refs.videoPlayer, this.options, function onPlayerReady() { console.log('onPlayerReady', this); }) }, beforeDestroy() { if (this.player) { this.player.dispose() } } } </script>

官网地址

最后

以上就是追寻方盒最近收集整理的关于简单使用videojs 播放m3u8格式的视频的全部内容,更多相关简单使用videojs内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部