码迷,mamicode.com
首页 > Web开发 > 详细

使用hls.js播放m3u8视频流

时间:2019-12-25 16:13:44      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:else   iss   install   listen   https   edm   mount   hub   des   


<template> <div class="video_con"> <video controls class="video" ref="video"></video> </div> </template> <script>
   // npm install hls.js -S let Hls = require(‘hls.js‘); export default { data() { return { hls: null } }, mounted() { this.getStream(‘url‘) }, methods: { getStream(source) { if (Hls.isSupported()) { this.hls = new Hls(); this.hls.loadSource(source); this.hls.attachMedia(this.$refs.video); this.hls.on(Hls.Events.MANIFEST_PARSED, () => { console.log("加载成功"); this.$refs.video.play(); }); this.hls.on(Hls.Events.ERROR, (event, data) => { // console.log(event, data); // 监听出错事件 console.log("加载失败"); }); } else if (this.$refs.video.canPlayType(‘application/vnd.apple.mpegurl‘)) { this.$refs.video.src = ‘https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8‘; this.$refs.video.addEventListener(‘loadedmetadata‘,function() { this.$refs.video.play(); }); } }, // 停止流 videoPause() { if (this.hls) { this.$refs.video.pause(); this.hls.destroy(); this.hls = null; } } } } </script>

使用hls.js播放m3u8视频流

标签:else   iss   install   listen   https   edm   mount   hub   des   

原文地址:https://www.cnblogs.com/troublehuan/p/12096691.html

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!