DCloud_UNI_GSQ
DCloud_UNI_GSQ
  • 发布:2019-01-02 21:04
  • 更新:2024-04-01 16:18
  • 阅读:39643

uni-app在H5平台使用video.js,以及播放m3u8格式的视频

分类:uni-app
  1. 创建模板文件index.html,在模版内引用video.js
<!DOCTYPE html>  
<html lang="zh-CN">  
    <head>  
        <meta charset="utf-8">  
        <meta http-equiv="X-UA-Compatible" content="IE=edge">  
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">  
        <title>  
            <%= htmlWebpackPlugin.options.title %>  
        </title>  
        <script>  
            document.addEventListener('DOMContentLoaded', function() {  
                document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'  
            })  
        </script>  
        <link rel="stylesheet" href="<%= htmlWebpackPlugin.options.baseUrl %>static/index.css" />  
        <link href="https://unpkg.com/video.js/dist/video-js.min.css" rel="stylesheet">  
        <script src="https://unpkg.com/video.js/dist/video.min.js"></script>  
    </head>  
    <body>  
        <noscript>  
            <strong>Please enable JavaScript to continue.</strong>  
        </noscript>  
        <div id="app"></div>  
        <!-- built files will be auto injected -->  
    </body>  
</html>
  1. 在manifest.json内配置index.html路径
  2. 在vue文件内使用video.js初始化播放器
<template>  
    <view class="content">  
        <view class="video-js" ref="video">  

        </view>  
    </view>  
</template>  

<script>  
    export default {  
        onReady() {  
            // #ifdef H5  
            var video = document.createElement('video')  
            video.id = 'video'  
            video.style = 'width: 300px;height: 150px;'  
            video.controls = true  
            var source = document.createElement('source')  
            source.src = 'http://yf.ugc.v.cztv.com/cztv/ugcvod/2018/04/14/A98CD7B26B06D94A5CEA56AA7D723572/h264_800k_mp4.mp4_playlist.m3u8'  
            video.appendChild(source)  
            this.$refs.video.$el.appendChild(video)  
            videojs('video')  
            // #endif  
        },  
        methods: {  

        }  
    }  
</script>  

<style>  

</style>

注意事项

  1. 示例工程见附件
  2. 如果视频源格式为m3u8,m3u8文件可能遇到跨域问题,请自行百度
9 关注 分享
Trust Stalker丶 dub 3***@qq.com 子衣 锦笑江湖 h***@163.com 2***@qq.com 9***@qq.com

要回复文章请先登录注册

q***@163.com

q***@163.com

好坑,onReady 渲染才执行,下次在进这个组建我怎么替换source ?????
2019-08-30 20:52
d***@qq.com

d***@qq.com

您好 打包后怎么用不了呀
2019-07-30 16:21