【视频】横屏播放,uniapp,微信小程序,可选择播放速度,暂停和继续播放


javascript 复制代码
<template>
	<view class="form1box u-f">
		<image src="@/static/img/fanhui.png" mode="" class="u-w-25.86 u-h-25.86 u-m-r-21" @click="leftClick"></image>
		
		<view class="content">
			<video id="myVideo"
			class="u-w-460"
			:style="{'height':winheight+'px'}"   
			autoplay
			:src="videosrc"
			object-fit='cover'
			:controls='true'
			:show-fullscreen-btn='false'
			:show-center-play-btn='false'
			:show-play-btn='false'
			@ended='endedFun'
			></video>
		</view>
		<view class="operate u-m-l-12" >
			<view class="u-flex" @click="zhFun">
				<image src="@/static/img/sw1.png" mode="" class="u-w-36.95 u-h-19.4 u-m-r-21.71" v-if="isZH"></image>
				<image src="@/static/img/sw.png" mode="" class="u-w-36.95 u-h-19.4 u-m-r-21.71" v-else></image>
				<text>添加中文朗读</text>
			</view>
			<view class="u-flex" @click="sjFun">
				<image src="@/static/img/suiji.png" mode="" class="u-w-36.48 u-h-36.48 u-m-r-21.24" v-if="issj"></image>
				<image src="@/static/img/zan1.png" mode="" class="u-w-36.48 u-h-36.48 u-m-r-21.24" v-else></image>
				<text> {{issj?'随机播放':'暂停'}}</text>
			</view>
			<view class="u-flex" @click="bofangFun">
				<image src="@/static/img/you.png" mode="" class="u-w-36.48 u-h-36.48 u-m-r-21.24" v-if="isbofang"></image>
				<image src="@/static/img/zan1.png" mode="" class="u-w-36.48 u-h-36.48 u-m-r-21.24" v-else></image>
				<text>{{isbofang?'自动播放':'暂停'}}</text>
			</view>
			<view class="bigbox">
				<view class="scrollbox" v-if="suduShow">
					<view 
					v-for="(item,i) in suduList" :key="i"
					class="u-m-b-10"
					:class="item.choose ? 'ac' :''"
					@click="suduFun(i)"
					>{{item.name}}X</view>
				</view>
				<view @click="suduShow=!suduShow" class="u-flex">
					<view class="sudu u-w-36.95 u-m-r-21.71">{{sudu}}</view>
					<text>播放速度</text>
				</view>
			</view>
			<view class="bigbox">
				<view class="scrollbox" v-if="scrollShow">
					<view 
					v-for="(item,i) in timeList" :key="i"
					class="u-m-b-10"
					:class="item.choose ? 'ac' :''"
					@click="timeFun(i)"
					>{{item.time}}s</view>
				</view>
				
				<view @click="scrollShow=!scrollShow" class="u-flex">
					<view class="sudu u-w-36.95 u-m-r-21.71">{{time}}s</view>
					<text>间隔距离</text>
				</view>
			
			</view>
		</view>
	</view>
</template>

<script>
	// import {
	//   xxx
	//  } from "@/api/index/index.js"
	export default {
		components: {},
		data() {
			return {
				winheight:0,
				videosrc:'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4', // 视频
				
				scrollShow:false, // 时间间隔默认不显示false
				timeList:[
					{choose:false,time:'1.0'},
					{choose:false,time:'1.5'},
					{choose:false,time:'2.0'},
					{choose:true,time:'2.5'},
					{choose:false,time:'3.0'},
					{choose:false,time:'3.5'},
					{choose:false,time:'4.0'},
					{choose:false,time:'4.5'},
					{choose:false,time:'5.0'},
				],
				time:'2.5' ,// 时间间隔 默认2.5s
				
				suduShow:false, // 播放速度默认不显示false
				suduList:[
					{choose:false,name:'0.25'},
					{choose:false,name:'0.5'},
					{choose:false,name:'0.75'},
					{choose:true,name:'1.0'},
					{choose:false,name:'1.25'},
					{choose:false,name:'1.5'},
					{choose:false,name:'1.75'},
					{choose:false,name:'2.0'},
					{choose:false,name:'2.5'},
				],
				sudu:'1.0' ,//播放速度 默认1.0X
				
				isZH:false, // 是否中文朗读 默认false否
				issj:true, // 是否随机播放 默认true是
				isbofang:true, // 是否自动播放 默认true是
			}
		},
		onLoad(option) {
			let that = this;
			uni.getSystemInfo({
				success: function (res) {
					that.winheight = res.windowHeight - 80;
				}
			});
			this.videoContext = uni.createVideoContext("myVideo", this);
			this.$nextTick(() => {
				this.videoContext.play();
			});
			
		},
		methods: {
			// 选中 时间间隔,自动默认循环和开始播放
			timeFun(i){
				this.suduShow = false; // 速度false
				this.timeList.forEach((item,index) => {
						if(i == index){
							item.choose = true;
							this.time = item.time;
							this.scrollShow = false;
						} else {
							item.choose = false;
						}
				});
			},
			// 选中 速度 
			suduFun(i){
				this.scrollShow = false; // 时间false
				this.suduList.forEach((item,index) => {
						if(i == index){
							item.choose = true;
							this.sudu = item.name;
							this.suduShow = false;
							// 播放速度
							this.videoContext.playbackRate(Number(item.name))
						} else {
							item.choose = false;
						}
				});
			},
			//  当播放到末尾时触发 ended 事件,先暂停再延迟多长时间重新播放
			endedFun(){
				let that = this;
				let a = Number(this.time)*1000;
				
				this.$nextTick(() => {
					this.videoContext.pause();
				});
				
				setTimeout(function() {
						console.log('延迟时间开始播放新的视频',a);
						// that.videoContext.play();
				}, a);
			},
			
			leftClick(){
				uni.navigateBack();
			},
			// 中文朗读
			zhFun(){
				this.isZH = !this.isZH;
			},
			// 随机播放
			sjFun(){
				this.issj = !this.issj;
			},
			// 播放或暂停
			bofangFun(){
				this.isbofang = !this.isbofang;
				if(this.isbofang){
					console.log('播放');
					this.$nextTick(() => {
						this.videoContext.play();
					});
				} else {
					console.log('暂停');
					this.$nextTick(() => {
						this.videoContext.pause();
					});
				}
			},
			
		},
	}
</script>


<style lang='scss' scoped>
	.form1box{
		padding: 40rpx 16rpx 7rpx 40rpx;
		box-sizing: border-box;
		height: 100vh;
		.operate{
			box-sizing: border-box;
			display: flex;
			justify-content: space-around;
			flex-direction: column;
			color: #000000;
			font-size: 12rpx;
			font-family: MicrosoftYaHei;
			padding: 20rpx 0;
			.sudu{
				color: #B0B0B0;
				font-family: Adobe Heiti Std R;
			}
			
			.bigbox{
				position: relative;
			}
			
			.scrollbox{
				box-sizing: border-box;
				position: absolute;
				/* top: -250rpx; */
				bottom:20rpx;
				left: 0rpx;
				background-color: #fff;
				width: 148rpx;
				height: 170rpx;
				overflow: auto;
				border: 1rpx solid #000000;
				color:#B0B0B0;
				font-size: 12rpx;
				font-family: MicrosoftYaHei;
				padding: 9rpx 12rpx;
				.ac{
					color: #000000;
				}
			}
			
		}
	}
</style>
相关推荐
断墨先生2 小时前
uniapp—android原生插件开发(3Android真机调试)
android·uni-app
MediaTea2 小时前
Pr 视频过渡:沉浸式视频 - VR 色度泄漏
音视频·vr
LNTON羚通3 小时前
算法定制LiteAIServer摄像机实时接入分析平台烟火检测算法的主要功能
音视频·视频监控
guai_guai_guai4 小时前
uniapp
前端·javascript·vue.js·uni-app
EasyCVR8 小时前
EHOME视频平台EasyCVR视频融合平台使用OBS进行RTMP推流,WebRTC播放出现抖动、卡顿如何解决?
人工智能·算法·ffmpeg·音视频·webrtc·监控视频接入
阿伟来咯~9 小时前
一些 uniapp相关bug
uni-app·bug
冷凝女子10 小时前
【QT】海康视频及openCv抓拍正脸接口
qt·opencv·音视频·海康
安步当歌11 小时前
【WebRTC】视频编码链路中各个类的简单分析——VideoStreamEncoder
音视频·webrtc·视频编解码·video-codec
顾北川_野11 小时前
Android CALL关于电话音频和紧急电话设置和获取
android·音视频
顶呱呱程序11 小时前
2-143 基于matlab-GUI的脉冲响应不变法实现音频滤波功能
算法·matlab·音视频·matlab-gui·音频滤波·脉冲响应不变法