用uniapp写一个播放视频首页页面代码
效果如下图所示




首页有导航栏,搜索框,和视频列表,
导航栏如下图

搜索框如下图

视频列表如下图

文件目录


视频首页页面代码如下
<template>
<view class="video-home">
<!-- 搜索栏 -->
<view class="search-bar">
<input type="text" placeholder="搜索视频..." v-model="searchQuery" @input="handleSearch" />
<button @click="handleSearch">搜索</button>
</view><!-- 视频分类导航 -->
<view class="category-tabs">
<scroll-view scroll-x class="tabs">
<view v-for="(category, index) in categories" :key="index"
:class="['tab-item', { 'active': activeCategory === category }]"
@click="changeCategory(category)">
{{ category }}
</view>
</scroll-view>
</view><!-- 视频列表 -->
<view class="video-list">
<block v-for="(item, index) in filteredVideos" :key="index">
<view class="video-item" @click="goToVideoDetail(item.id)">
<video ref="videos" :src="item.videoUrl" class="video-thumbnail" controls></video>
<view class="video-content">
<text class="video-title">{{ item.title }}</text>
<text class="video-summary">{{ item.summary }}</text>
<text class="video-date">{{ formatDate(item.date) }}</text>
<text class="video-duration">{{ formatDuration(item.duration) }}</text>
</view>
</view>
</block>
</view>
</view>
</template><script>
export default {
data() {
return {
searchQuery: '',
activeCategory: '推荐',
categories: ['推荐', '热门', '最新', '科技', '娱乐', '生活'],
videoItems: [
// 示例视频条目,请替换为实际数据或从后端获取的数据
{ id: 1, title: '视频标题1', summary: '视频摘要...', date: new Date(), duration: 360, videoUrl: '/static/videos/1.mp4', category: '推荐' },
{ id: 2, title: '视频标题2', summary: '视频摘要...', date: new Date(), duration: 540, videoUrl: '/static/videos/2.mp4', category: '热门' },
{ id: 3, title: '视频标题3', summary: '视频摘要...', date: new Date(), duration: 360, videoUrl: '/static/videos/3.mp4', category: '推荐' },
{ id:4, title: '视频标题4', summary: '视频摘要...', date: new Date(), duration: 540, videoUrl: '/static/videos/4.mp4', category: '热门' },
{ id: 5, title: '视频标题5', summary: '视频摘要...', date: new Date(), duration: 360, videoUrl: '/static/videos/5.mp4', category: '推荐' },
{ id: 6, title: '视频标题6', summary: '视频摘要...', date: new Date(), duration: 540, videoUrl: '/static/videos/6.mp4', category: '热门' },
{ id:7, title: '视频标题7', summary: '视频摘要...', date: new Date(), duration: 360, videoUrl: '/static/videos/7.mp4', category: '推荐' },
{ id:8, title: '视频标题8', summary: '视频摘要...', date: new Date(), duration: 540, videoUrl: '/static/videos/8.mp4', category: '热门' },
{ id:9, title: '视频标题9', summary: '视频摘要...', date: new Date(), duration: 360, videoUrl: '/static/videos/live1.mp4', category: '推荐' },
{ id: 10, title: '视频标题10', summary: '视频摘要...', date: new Date(), duration: 540, videoUrl: '/static/videos/live2.mp4', category: '热门' },
{ id: 1, title: '视频标题1', summary: '视频摘要...', date: new Date(), duration: 360, videoUrl: '/static/videos/1.mp4', category: '推荐' },
{ id: 2, title: '视频标题2', summary: '视频摘要...', date: new Date(), duration: 540, videoUrl: '/static/videos/2.mp4', category: '热门' },
{ id: 3, title: '视频标题3', summary: '视频摘要...', date: new Date(), duration: 360, videoUrl: '/static/videos/3.mp4', category: '推荐' },
{ id:4, title: '视频标题4', summary: '视频摘要...', date: new Date(), duration: 540, videoUrl: '/static/videos/4.mp4', category: '热门' },
{ id: 5, title: '视频标题5', summary: '视频摘要...', date: new Date(), duration: 360, videoUrl: '/static/videos/5.mp4', category: '推荐' },
{ id: 6, title: '视频标题6', summary: '视频摘要...', date: new Date(), duration: 540, videoUrl: '/static/videos/6.mp4', category: '娱乐' },
{ id:7, title: '视频标题7', summary: '视频摘要...', date: new Date(), duration: 360, videoUrl: '/static/videos/7.mp4', category: '科技' },
{ id:8, title: '视频标题8', summary: '视频摘要...', date: new Date(), duration: 540, videoUrl: '/static/videos/8.mp4', category: '最新' },
{ id:9, title: '视频标题9', summary: '视频摘要...', date: new Date(), duration: 360, videoUrl: '/static/videos/live1.mp4', category: '推荐' },
{ id: 10, title: '视频标题10', summary: '视频摘要...', date: new Date(), duration: 540, videoUrl: '/static/videos/live2.mp4', category: '热门' },
],
currentPlaying: null // 用来追踪当前正在播放的视频元素
};
},
computed: {
filteredVideos() {
return this.videoItems.filter(item =>
(this.searchQuery ? item.title.includes(this.searchQuery) : true) &&
(this.activeCategory === '推荐' || item.category === this.activeCategory)
);
}
},
methods: {
goToVideoDetail(id) {
uni.navigateTo({
url: `/pages/VideoDetail/VideoDetail?id=${id}`
});
},
handleSearch(event) {
// 如果需要对输入进行实时响应,可以在这里实现
this.searchQuery = event.target.value;
},
changeCategory(category) {
this.activeCategory = category;
},
playVideo(videoUrl) {
const videos = this.$refs.videos || [];
videos.forEach(video => {
if (video.src === videoUrl && this.currentPlaying !== video) {
this.pauseCurrent();
video.play();
this.currentPlaying = video;
} else if (this.currentPlaying === video) {
video.pause();
this.currentPlaying = null;
}
});
},
pauseCurrent() {
if (this.currentPlaying) {
this.currentPlaying.pause();
}
},
formatDate(date) {
const options = { year: 'numeric', month: 'long', day: 'numeric' };
return new Intl.DateTimeFormat('zh-CN', options).format(date);
},
formatDuration(seconds) {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
}
}
};
</script><style scoped>
/* 样式 */
.video-home {
padding: 100px;
}.search-bar {
display: flex;
align-items: center;
margin-bottom: 10px;
}.search-bar input {
flex: 1;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
}.search-bar button {
margin-left: 5px;
padding: 8px 16px;
}.category-tabs {
margin-bottom: 10px;
}.tabs {
white-space: nowrap;
}.tab-item {
display: inline-block;
padding: 8px 16px;
cursor: pointer;
}.tab-item.active {
color: #3cc51f;
font-weight: bold;
}.video-list .video-item {
display: flex;
margin-bottom: 10px;
padding: 10px;
background-color: #fff;
border-radius: 4px;
}.video-thumbnail {
width: 400px;
height: 400px;
margin-right: 10px;
border-radius: 4px;
}
/* 调整视频缩略图大小 */
.video-thumbnail {
width: 100%; /* 让缩略图占满整个视频容器 */
height: auto; /* 维持视频的原始比例 */
border-radius: 8px; /* 匹配视频项的圆角 */
margin-right: 20px; /* 增大右侧外边距,给文字内容留出更多空间 */
}
.video-content {
flex: 2;
}.video-title {
font-size: 16px;
font-weight: bold;
margin-bottom: 5px;
}.video-summary {
font-size: 14px;
color: #666;
}.video-date,
.video-duration {
font-size: 12px;
color: #999;
}.video-duration {
margin-top: 5px;
}
/* 视频列表样式 */
.video-list {
display: flex;
flex-wrap: wrap; /* 允许换行 */
gap: 20px; /* 设置项目之间的间距 */
margin: -10px; /* 调整外边距以对齐内部间距 */
}</style>
相关文章:
用uniapp写一个播放视频首页页面代码
效果如下图所示 首页有导航栏,搜索框,和视频列表, 导航栏如下图 搜索框如下图 视频列表如下图 文件目录 视频首页页面代码如下 <template> <view class"video-home"> <!-- 搜索栏 --> <view class…...
【视觉SLAM:八、后端Ⅰ】
视觉SLAM的后端主要解决状态估计问题,它是优化相机轨迹和地图点的过程,从数学上看属于非线性优化问题。后端的目标是结合传感器数据,通过最优估计获取系统的状态(包括相机位姿和场景结构),在状态估计过程中…...
PaddleOCROCR关键信息抽取训练过程
步骤1:python版本3.8.20 步骤2:下载代码,安装依赖 git clone https://gitee.com/PaddlePaddle/PaddleOCR.git pip uninstall opencv-python -y # 安装PaddleOCR的依赖 ! pip install -r requirements.txt # 安装关键信息抽取任务的依赖 !…...
用Python操作字节流中的Excel文档
Python能够轻松地从字节流中加载文件,在不依赖于外部存储的情况下直接对其进行读取、修改等复杂操作,并最终将更改后的文档保存回字节串中。这种能力不仅极大地提高了数据处理的灵活性,还确保了数据的安全性和完整性,尤其是在网络…...
python 桶排序(Bucket Sort)
桶排序(Bucket Sort) 桶排序是一种分布式排序算法,适用于对均匀分布的数据进行排序。它的基本思想是:将数据分到有限数量的桶中,每个桶分别排序,最后将所有桶中的数据合并。 桶排序的步骤: 划…...
Elasticsearch:探索 Elastic 向量数据库的深度应用
Elasticsearch:探索 Elastic 向量数据库的深度应用 一、Elasticsearch 向量数据库简介 1. Elasticsearch 向量数据库的概念 Elasticsearch 本身是一个基于 Lucene 的搜索引擎,提供了全文搜索和分析的功能。随着技术的发展,Elasticsearch 也…...
【每日学点鸿蒙知识】属性变量key、waterflow卡顿问题、包无法上传、Video控件播放视频、Vue类似语法
1、HarmonyOS 属性变量常量是否可以作为object对象的key? a: object new Object() this.a[Constants.TEST_KEY] "456" 可以先定义,再赋值 2、首页点击回到waterflow的首节点,0~index全部节点被重建,导致卡顿 使用s…...
小程序中引入echarts(保姆级教程)
hello hello~ ,这里是 code袁~💖💖 ,欢迎大家点赞🥳🥳关注💥💥收藏🌹🌹🌹 🦁作者简介:一名喜欢分享和记录学习的在校大学生…...
基于 Node.js 的 ORM(对象关系映射)工具——Sequelize介绍与使用,并举案例分析
便捷性介绍 支持多种数据库,包括 PostgreSQL、MySQL、MariaDB、SQLite 和 Microsoft SQL Server。Sequelize 提供了丰富的功能,帮助开发者用 JavaScript(或 TypeScript)代码操作数据库,而无需直接书写 SQL 语句。 Se…...
python 插入排序(Insertion Sort)
插入排序(Insertion Sort) 插入排序是一种简单的排序算法。它的基本思想是:将数组分为已排序部分和未排序部分,然后逐个将未排序部分的元素插入到已排序部分的正确位置。插入排序类似于整理扑克牌的过程。 插入排序的步骤&#…...
电子应用设计方案81:智能AI冲奶瓶系统设计
智能 AI 冲奶瓶系统设计 一、引言 智能 AI 冲奶瓶系统旨在为父母或照顾者提供便捷、准确和卫生的冲奶服务,特别是在夜间或忙碌时,减轻负担并确保婴儿获得适宜的营养。 二、系统概述 1. 系统目标 - 精确调配奶粉和水的比例,满足不同年龄段婴…...
JAVA高并发总结
JAVA高并发编程总结 在现代应用中,高并发编程是非常重要的一部分,尤其是在分布式系统、微服务架构、实时数据处理等领域。Java 提供了丰富的并发工具和技术,帮助开发者在多线程和高并发的场景下提高应用的性能和稳定性。以下是 Java 高并发编…...
【AIGC】使用Java实现Azure语音服务批量转录功能:完整指南
文章目录 引言技术背景环境准备详细实现1. 基础架构设计2. 实现文件上传功能3. 提交转录任务crul4. 获取转录结果 使用示例结果示例最佳实践与注意事项总结 引言 在当今数字化时代,将音频内容转换为文本的需求越来越普遍。无论是会议记录、视频字幕生成,…...
arcgis模版空库怎么用(一)
这里以某个项目的数据为例: 可以看到,属性表中全部只有列标题,无数据内容 可能有些人会认为空库是用来往里面加入信息的,其实不是,正确的用法如下: 一、下图是我演示用的数据,我们可以看到其中…...
【电机控制】基于STC8H1K28的六步换向——方波驱动(软件篇)
【电机控制】基于STC8H1K28的六步换向——方波驱动(软件篇) 文章目录 [TOC](文章目录) 前言一、main.c二、GPIO.c三、PWMA.c四、ADC.c五、CMP.c六、Timer.c七、PMSM.c八、参考资料总结 前言 【电机控制】STC8H无感方波驱动—反电动势过零检测六步换向法 …...
小程序配置文件 —— 13 全局配置 - window配置
全局配置 - window配置 这里讲解根目录 app.json 中的 window 字段,window 字段用于设置小程序的状态栏、导航条、标题、窗口背景色; 状态栏:顶部位置,有网络信号、时间信息、电池信息等;导航条:有一个当…...
全球域名市场科普之域名交易平台介绍——Sedo与Afternic
关于Dynadot Dynadot是通过ICANN认证的域名注册商,自2002年成立以来,服务于全球108个国家和地区的客户,为数以万计的客户提供简洁,优惠,安全的域名注册以及管理服务。 Dynadot平台操作教程索引(包括域名邮…...
leetcode108:将有序数组转化为二叉搜索树
给你一个整数数组 nums ,其中元素已经按 升序 排列,请你将其转换为一棵 平衡 二叉搜索树。 示例 1: 输入:nums [-10,-3,0,5,9] 输出:[0,-3,9,-10,null,5] 解释:[0,-10,5,null,-3,null,9] 也将被视为正确…...
截图技术方案
安卓截屏技术附带悬浮窗自动存储功能_安卓截图浮窗-CSDN博客 https://chat.baidu.com/search?dyTabStrMCwxMiwzLDEsMiwxMyw3LDYsNSw5&pdcsaitab&setypecsaitab&extParamsJson%7B%22apagelid%22%3A%2210990774271994514433%22%2C%22enter_type%22%3A%22a_ai_index%…...
程序员测试日常小工具
作为一名程序员,或者测试人员,日常工作最常用的工具有哪些,截图,截图漂浮,翻译,日期处理,api调用..., 当你拿到一串报文后,想要json转换时,是不是要打…...
告别环境配置烦恼:手把手教你搞定Qualcomm AI Engine Direct在Windows和Linux下的开发环境
高通AI引擎开发环境全攻略:Windows与Linux双平台实战指南 第一次打开Qualcomm AI Engine Direct SDK的压缩包时,你可能会有种面对乐高零件箱的错觉——各种架构的库文件、不同平台的工具链、错综复杂的依赖关系扑面而来。作为曾在多个芯片平台迁移AI模型…...
深圳 EMC 整改避坑指南:别让一次失败,毁掉整个产品周期
深圳,这座全球电子产业的心脏,每天都有上百款新产品从这里走向世界。但 2026 年 4 月 FCC 新规的落地,给无数深圳电子企业浇了一盆冷水:单次海外测试费暴涨至 6-10 万元,周期拉长到 6-12 周,一次整改失败&a…...
CLup使用:一键创建Doris存算一体集群
通过 CLup 数据库管理平台的可视化界面,一键自动化部署 Apache Doris 存算一体集群,自动完成环境检查、配置初始化、节点部署与集群注册,无需手动执行复杂的 FE/BE 配置与启动命令,大幅降低部署门槛。CLup安装部署请看:…...
电脑突然‘哑巴’了?保姆级排查指南:从服务、驱动到系统修复,一步步搞定Win10音频问题
电脑突然‘哑巴’了?保姆级排查指南:从服务、驱动到系统修复,一步步搞定Win10音频问题 右下角的小喇叭突然打上红叉,视频会议开到一半突然失声,游戏打到关键处却没了音效——这些场景恐怕每个Windows 10用户都遭遇过。…...
AI率总超标?2026年AI论文平台排行榜权威发布,轻松定稿不是梦!
写论文效率低、熬夜赶稿、查重总不通过?别慌!2026 年最新 AI 论文写作工具合集来了,覆盖选题、大纲、初稿、润色、降重、格式、文献引用全流程,帮你精准匹配最适合的学术助手,彻底告别论文内耗!Ἴ…...
深度解析XGBoost环境配置:从零构建高性能梯度提升库
深度解析XGBoost环境配置:从零构建高性能梯度提升库 【免费下载链接】xgboost Scalable, Portable and Distributed Gradient Boosting (GBDT, GBRT or GBM) Library, for Python, R, Java, Scala, C and more. Runs on single machine, Hadoop, Spark, Dask, Flink…...
OPPO Pad 6 官宣!3K 柔光屏,5 月 25 日发布
5月18日,OPPO 正式官宣全新平板 OPPO Pad 6,定档 5月25日与 Reno16 系列同台发布。作为迭代款,它没有激进改款,而是在成熟设计上精准升级 —— 核心芯片、屏幕、续航、存储与手写体验全面优化,瞄准学生网课、大屏娱乐、…...
告别Modelsim命令行!用Notepad++插件NppExec一键检查Verilog语法(附详细配置命令)
硬件工程师的效率革命:Notepad与Verilog语法检查的终极整合方案 在数字电路设计领域,Verilog作为主流硬件描述语言,其语法检查是每位工程师日常工作中不可或缺的环节。传统工作流程中,工程师们不得不在文本编辑器与EDA工具之间频繁…...
docker启动线程创建异常 pthread_create EPERM | RuntimeError: can‘t start new thread
直接说答案,着急就复制过去使用 docker配置 增加对应权限配置参数即可 --privileged 如果上述不行,docker配置 使用组合方式 --privileged \ --ulimit nproc65535:65535 \ --ulimit nofile65535:65535 \详细解释 下面逐项解释这些 Docker 参数的作用、…...
从MySQL到Neo4j:用你熟悉的SQL思维,快速上手CQL创建第一个知识图谱
从MySQL到Neo4j:用SQL思维快速构建知识图谱的实战指南 当你在MySQL中熟练编写JOIN查询时,是否想过这些表关系本质上就是一张网?图数据库将这种网状关系作为一等公民,而Neo4j正是这个领域的佼佼者。本文会带你用熟悉的SQL视角&…...
