欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > uniapp 开屏视频 以及解决开屏视频播放前短暂白屏或黑屏的情况

uniapp 开屏视频 以及解决开屏视频播放前短暂白屏或黑屏的情况

2024/10/24 8:20:04 来源:https://blog.csdn.net/weixin_45563734/article/details/140371552  浏览:    关键词:uniapp 开屏视频 以及解决开屏视频播放前短暂白屏或黑屏的情况

uniapp 开屏视频 以及解决开屏视频播放前短暂白屏或黑屏的情况

  1. 废话不多说 直接上代码
<template><view class=""><video :style='{opacity: play }' :preferred-peak-bit-rate="284" :autoplay="true" :loop="true" object-fit='fill'class="video" id="videos" :enable-progress-gesture="true" :controls="false" @ended="" @play="onPlay"@timeupdate="videoEnd" :show-fullscreen-btn="true" @ended='goIndex' :src="videoUrl" :show-center-play-btn="false"@loadedmetadata="loadedmetadata"></video><view class="btn" @click='goIndex'>跳过&nbsp;&nbsp;{{duration}}</view><image  :style='{opacity: play==1?0:1 }' style="position: absolute;left: 0;top: 0; width: 100%;height: 100vh;":src="videoData.videoAddress" mode=""></image></view>
</template><script>export default {data() {return {videoUrl: '',videoData: {videoAddress: '',addressSort: 0},duration: "",play: 0,videoContext: null,recommendFn: null}},onLoad() {// 调用接口 获取 开屏视频  以及 占位图片this.getSwiper()},onShow() {// 每次计入页面都接着上次倒计时继续if (!this.recommendFn && this.duration!=="") {this.recommendFn = setInterval(() => {if (this.duration >= 1) {this.duration = parseInt(this.duration) - 1} else {clearInterval(this.recommendFn)this.recommendFn = nullthis.goIndex()}}, 1000)}},onHide() {// 页面隐藏时  停止计时clearInterval(this.recommendFn)this.recommendFn = null},methods: {getSwiper() {let that = this// 获取 开屏视频  以及 占位图片  和 倒计时// 更具自及的需要 也可直接写死that.$uniApi.dataRequestNoLoading('get', `base/app/v1/commonVideo/list`).then(res => {// 视频urlthat.videoUrl = res.data[0].videoUrl// 图片urlthat.videoData.videoAddress = res.data[0].indexImgUrl// 倒计时that.duration = res.data[0].videoDuration// 开始倒计时if (!that.recommendFn) {that.recommendFn = setInterval(() => {if (that.duration >= 1) {that.duration = parseInt(that.duration) - 1} else {clearInterval(that.recommendFn)that.recommendFn = null// 倒计时结束后  跳转页面that.goIndex()}}, 1000)}that.videoEnd()}).catch(err => {})},loadedmetadata(e) {let that = this// 此处延时 就是为了解决白屏或黑屏的情况setTimeout(() => {that.play = 1}, 500)},goIndex() {uni.switchTab({url: '倒计时完成跳转到其他页面'})},onPlay() {let that = this// 此处延时 就是为了解决白屏或黑屏的情况setTimeout(() => {that.play = 1}, 500)},videoEnd(e) {}}}
</script><style>.video {width: 100%;height: 100vh;}.btn {width: 170rpx;height: 54rpx;background: rgba(255, 255, 255, 0.5);border-radius: 30rpx;border: 1rpx solid #FFFFFF;font-family: Source Han Sans SC, Source Han Sans SC;font-weight: 400;font-size: 26rpx;color: #222222;line-height: 30rpx;position: absolute;top: 240rpx;right: 22rpx;line-height: 54rpx;text-align: center;z-index: 10;}
</style>
  1. 在这里插入图片描述

  2. ok 搞定! 可直接用

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com