uniapp 随机抽取视频播放

news/2024/10/1 21:37:49

编写了一个视频播放界面,然后再从后端再随机读取10条视频信息,最后在我们前端app的页面上显示出来。

复制代码
<template><view class="index"><transition name="fade"><view class="video-container" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd"><viewv-if="videoList[currentIndex].videoUrl":src="videoList[currentIndex].videoUrl" :key="currentIndex" class="video-element" style="height:200px;width: 350px;" ref="videoElement"autoplay></view></view></transition></view>
</template><script>
import indexHeader from '@/components/index-header.vue';export default {components: {indexHeader},data() {return {title: 'Hello',videoList: [],currentIndex: 0,startY: 0,}},onShow() {uni.request({url:this.$BASE_URL.BASE_URL+'/getvideo',method:'GET',success: (res) => {this.videoList=res.data.data;console.log(this.videoList)}})},methods: {touchStart(e) {this.startY = e.changedTouches[0].clientY;},touchMove(e) {if (this.startY === 0) {return;}const deltaY = e.changedTouches[0].clientY - this.startY;if (deltaY > 50) {this.prevVideo();} else if (deltaY < -50) {this.nextVideo();}},touchEnd() {this.startY = 0;},headerSwitch(val) {this.currentIndex = 0; // 切换到第一个视频},prevVideo() {this.currentIndex = Math.max(0, this.currentIndex - 1); // 切换到上一个视频},nextVideo() {this.currentIndex = Math.min(this.videoList.length - 1, this.currentIndex + 1); // 切换到下一个视频}},created() {this.headerSwitch();},
}
</script><style lang="less">.index {display: flex;flex-direction: column;justify-content: center;background-color: #333333;height: 100vh;}.video-container {display: flex;justify-content: center;margin-top: 20px;overflow: hidden;}.video-element {width: 100%;max-width: 500px;}.fade-enter-active, .fade-leave-active {transition: opacity 0.5s;}.fade-enter, .fade-leave-to {opacity: 0;}.video-container {position: relative;width: 100%;max-width: 350px;margin: 0 auto;overflow: hidden;border-radius: 8px;box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);}.video-container {position: relative;width: 100%;max-width: 100%;max-height: 100vh; /* 限制视频的最大高度为视窗高度 */margin: 0 auto;overflow: hidden;
}/* 视频元素样式 */
.video-element {width: 100%;height: auto;display: block;
}/* 渐变效果 */
.fade-enter-active, .fade-leave-active {transition: opacity 0.5s;
}
.fade-enter, .fade-leave-to {opacity: 0;
}
</style>
复制代码

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ryyt.cn/news/44960.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

uniapp手机号认证注册的一个页面

今天主要在uniapp设计了一个通过手机号认证注册的一个页面,但是今天只完成了前端页面的部分。并且能成功的连接上对应的后端地址。<template><view class="container"><view class="logo"><!-- 这里放置你的应用 logo --><ima…

增补博客 第二十九篇 计算机网络复习四

第五章 运输层 1.运输层的作用 运输层向它上面的应用层提供通信服务(提供端到端,进程到进程的可靠通信),为运行在不同host上的进程提供逻辑通信,向高层用户屏蔽通信子网的细节 2.UDP和TCP的特点,及使用它们的应用程序,熟知端口号 UDP和TCP的特点:UDP支持单播、多播、广…

LeetCode 633 Sum of Square Numbers All In One

LeetCode 633 Sum of Square Numbers All In One 633. Sum of Square Numbers Math.sqrt Math.trunc Math.powLeetCode 633 Sum of Square Numbers All In OneSum of Square NumberssolutionsMath.sqrt / 平方根function judgeSquareSum(c: number): boolean {let max = Math.t…

又跳槽!3年Java经验收割成都大厂的面试心得(干货满满文末有福利)

中厂->阿里->字节,成都->杭州->成都 系列文章目录和关于我 0.前言 笔者在不足两年经验的时候从成都一家金融科技中厂跳槽到杭州阿里淘天集团,又于今年5月份从杭州淘天跳槽到成都字节。自认为自己在面试这方面有一点心得,处于记录和分享的目的便有了此文,此文纯…

leetcode 206. 反转链表

题目描述 206. 反转链表给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。示例 1:输入:head = [1,2,3,4,5] 输出:[5,4,3,2,1]示例 2:输入:head = [1,2] 输出:[2,1]示例 3: 输入:head = [] 输出:[] 提示:链表中节点的数目范围是 [0, 5000],-5000 <= …

AgileConfig-1.9.4 发布,支持 OpenTelemetry

Hello 大家好,最新版的 AgileConfig 1.9.4 发布了。现在它可以通过 OpenTelemetry 对外提供 logs,traces,metrics 三个维度的数据。用户可以自由选择支持 otlp 协议的工具来进行查询与分析。比如 Seq,loki,prometheus, grafana 等等。 本来 AgileConfig 的日志是通过 Nlog…

实验七

TASK1点击查看代码 // 将图书信息写入文本文件data1.txt // 再从文件中读取图书信息,打印输出到屏幕上,并显示行号#include <stdio.h>#define N 80 #define M 100typedef struct {char name[N]; // 书名 char author[N]; // 作者 } Book;// 函数声明 void func1(); …