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

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

要回复文章请先登录注册

G_shenren

G_shenren

Cannot read properties of undefined (reading '$el')根据模版写的时候一直出现 Cannot read properties of undefined (reading '$el')这个错误是什么问题
2024-04-01 16:18
吕地瓜

吕地瓜

回复 DCloud_UNI_GSQ :
可不可以做在manifest里,有需求的人可以开启。
2023-02-26 18:15
DCloud_UNI_GSQ

DCloud_UNI_GSQ (作者)

回复 吕地瓜 :
解析库不小,后续要求的人多了会考虑内置,否则增加的大小会体现在所有人的项目上。
2023-02-23 17:24
吕地瓜

吕地瓜

希望官方的video组件尽快兼容h5 m3u8
2023-02-22 19:09
爬坑之路

爬坑之路

回复 7***@qq.com :
你解决了嘛
2023-02-22 18:11
1***@qq.com

1***@qq.com

回复 1***@qq.com :
https://ask.dcloud.net.cn/question/152773
这是发的求助贴
2022-09-07 14:14
1***@qq.com

1***@qq.com

H5打包后样式失效了,请问怎么解决?
2022-09-07 14:14
t***@163.com

t***@163.com

写成组件的形式在页面中import进来就变成黑的了,请问有什么办法吗?救急(●'◡'●)
2022-04-07 17:12
1***@qq.com

1***@qq.com

运行demo也会报 The media could not be loaded, either because the …rk failed or because the format is not supported.
2022-01-26 17:17
44596296

44596296

样式为什么全部解析错误了?
2022-01-04 13:46