uniapp:轮播里如何加入视频

template代码

主要使用uniapp swiper 根据后端传递type判断是图片,还是视屏

<view class="screen-swiper">
		<swiper style="height: 900rpx;" @change="change" class="screen-swiper" indicator-dots="true" circular="true" :autoplay="!autoplay">
			<swiper-item style="width: 750rpx;height: 900rpx;" @click="PlayVideo(item)" v-for="(item, index) in videoList" :key="item.id">
				<image style="width: 750rpx;height: 900rpx;" v-if="!item.isPlay" :src="item.src" mode="aspectFill"></image>	
				<video style="width: 750rpx;height: 900rpx;" v-else id="myVideo" :src="item.vide" :autoplay="true" :enable-progress-gesture="false" loop muted show-play-btn controls objectFit="cover" @pause="suspend" @ended="suspend"></video>
			</swiper-item>
			<swiper-item style="width: 750rpx;height: 900rpx;" v-for="(item, index) in imageList" :key="item.id"><image style="width: 750rpx;height: 900rpx;" :src="item.src" mode="aspectFill"></image></swiper-item>
		</swiper>
	</view>  

script内代码

data代码

autoplay: false,
list: [
	{
	id: '',
	isPlay: false,
	type: 1,
	src: ''
	}
]

computed代码

videoList() {
	return this.list.filter(item => {
		return item.type == 2;
	});
},
imageList() {
	return this.list.filter(item => {
		return item.type == 1;
	});
}

onReady代码

this.videoContext = uni.createVideoContext('myVideo');

methods 代码

change(e) {
	if (e.detail.current != 0) {
		this.list[0].isPlay = false;
		that.autoplay = false;
		if(this.list[0].type==2)
		that.videoContext.pause();
	}
},
PlayVideo(item) {
	if (item.isPlay == false) {
		item.isPlay = true;
		that.videoContext.play();
		that.autoplay = true;
	} else {
		item.isPlay = false;
		that.autoplay = false;
		that.videoContext.pause();
	}
},
suspend(i) {
	if (that.autoplay == true) {
		that.autoplay = false;
	}
}

css代码 根据自己的方式调

.screen-swiper {
	min-height: 675upx;
}

.screen-swiper {
	width: 750rpx;
}

欢迎点赞收藏


  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值