- 创建模板文件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>
- 在manifest.json内配置index.html路径
- 在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>
注意事项
- 示例工程见附件
- 如果视频源格式为m3u8,m3u8文件可能遇到跨域问题,请自行百度