<template>
<view>
<video id="myVideo" v-show="show" :src="url" object-fit="cover" @ended="ended"></video>
<view class="content">
<button type="primary" @click="play">播放</button>
</view>
</view>
</template>
<script>
let videoContext
let video_url
export default {
data() {
return {
show: false,
url: ""
}
},
mounted() {
videoContext = uni.createVideoContext('myVideo')
uni.showLoading({
title:"加载中..."
})
uni.downloadFile({
url: "https://www.w3school.com.cn/example/html5/mov_bbb.mp4",
success: (res) => {
if (res.statusCode === 200) {
video_url = res.tempFilePath
console.log(res.tempFilePath)
uni.hideLoading()
}
}
});
},
methods: {
play() {
this.url = video_url
this.show = true
videoContext.play()
},
ended() {
console.log("播放结束")
}
}
}
</script>
<style>
.content {
display: flex;
align-items: center;
justify-content: center;
width: 100vw;
height: 100vh;
background-color: red;
z-index: 9999;
}
#myVideo {
position: absolute;
z-index: 1;
}
</style>
- 发布:2022-10-18 14:21
- 更新:2023-01-18 13:33
- 阅读:1033
产品分类: uniapp/小程序/QQ
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: 正式
HBuilderX版本号: 3.6.7
第三方开发者工具版本号: v0.702209052
基础库版本号: 1.57.1
项目创建方式: HBuilderX
示例代码:
操作步骤:
上面的代码示例
上面的代码示例
预期结果:
视频播放结束后回调
视频播放结束后回调
实际结果:
无回调
无回调
bug描述:
换成vue2或者安卓都能正常