【视频】横屏播放,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>
相关推荐
mo47763 小时前
Webrtc音频模块(四) 音频采集
音视频·webrtc
icy、泡芙3 小时前
T527-----音频调试
linux·驱动开发·音视频
易我数据恢复大师3 小时前
怎么提取音频保存到本地?电脑音频提取方法
音视频·软件·音频提取
野蛮的大西瓜3 小时前
开源呼叫中心中,如何将ASR与IVR菜单结合,实现动态的IVR交互
人工智能·机器人·自动化·音视频·信息与通信
兔C4 小时前
微信小程序的轮播图学习报告
学习·微信小程序·小程序
用户48062260414156 小时前
使用uniapp开发微信小程序-框架搭建
微信小程序·uni-app
嘟嘟实验室6 小时前
微信小程序xr-frame透明视频实现
微信小程序·ffmpeg·音视频·xr
红米饭配南瓜汤7 小时前
WebRTC服务质量(09)- Pacer机制(01) 流程概述
网络·音视频·webrtc
TttHhhYy8 小时前
uniapp+vue开发app,蓝牙连接,蓝牙接收文件保存到手机特定文件夹,从手机特定目录(可自定义),读取文件内容,这篇首先说如何读取,手机目录如何寻找
开发语言·前端·javascript·vue.js·uni-app
Funky_oaNiu8 小时前
uniapp实现按钮防重复点击(防抖)完整解决方案
uni-app