【vue】el-carousel实现视频自动播放与自动切换到下一个视频功能:

文章目录

        • 一、原因:
        • 二、实现代码:
        • 三、遇到的问题:
            • 【1】问题:el-carousel页面的视频不更新
            • 【2】问题:多按几次左按钮,其中跳过没有播放的视频没有销毁,造成再次自动播放时会跳页


一、原因:

由于后端无法实现将多条视频拼接为一条视频,所以更改为由前端实现页面视频自动播放功能和播放完后,自动切换到下一个视频功能

二、实现代码:
<template><div class="preview-content" v-loading="loading"><el-tabs v-model="activeName" @tab-click="tabClick"><!-- 视频预览 --><el-tab-pane v-if="DisplayList.includes('video')" name="video" :label="`视频预览【${videoList.length}`"><div v-if="videoList.length > 0" class="preview-content-box"><el-carousel ref="videoCarousel" @change="autoPlayVideo" :autoplay="false" :loop="false" style="width:100%"height="540px" :initial-index="0" :key="(Date.parse(new Date()) / 1000)" arrow="always"indicator-position="none"><el-carousel-item v-for="(item, index) in videoList" :key="index"><h2>{{ index + 1 }}/{{ videoList.length }}</h2><video autoplay :muted="false" controls preload :id="`video-${index}`" width=100% height="100%"><source :src="item" type="video/mp4" /><object type="application/x-shockwave-flash" data="myvideo.swf"><param name="movie" value="myvideo.swf" /><param name="flashvars" value="autostart=true&amp;file=myvideo.swf" /></object>当前浏览器不支持video直接播放,点击这里下载视频:<a :href="item">下载视频</a></video></el-carousel-item></el-carousel></div><div v-else class="noData">无视频</div></el-tab-pane></el-tabs></div>
</template><script>
export default {props: {DisplayList: {type: Array,default() {return ['img', 'video', 'imgBYWeight', 'imgBYCar', 'imgBYUpload']}},},data() {return {activeName: 'img',loading: false,videoList: [],//视频列表player: [],};},methods: {loadData(record, type) {const that = this;console.log('图片/视频预览:', record)that.activeName = (type && type != null && type != undefined && that.DisplayList.includes(type)) ? type : that.DisplayList.length > 0 ? that.DisplayList[0] : 'img'that.videoList = []             //视频列表if (!(typeof record == 'object') || Object.keys(record).length == 0) { return }that.loading = true// 视频列表if (that.DisplayList.includes('video')) {record.videoList && record.videoList.length > 0 ? that.videoList = [...that.pushArr(record.videoList)] : null;record.allVideoList && record.allVideoList.length > 0 ? that.videoList = [...that.videoList, ...that.pushArr(record.allVideoList)] : null;this.$nextTick(() => {that.videoList.length > 0 ? that.$refs.videoCarousel.setActiveItem(0) : null;that.player = []that.sleep(1000).then(() => { that.activeName == 'video' ? that.autoPlayVideo(0) : null; })})}that.loading = false;},// 数组遍历判断是否需要拼接地址pushArr(arr) {if (!Array.isArray(arr) || arr.length == 0) { return [] }let newArr = []for (let index = 0; index < arr.length; index++) {const item = arr[index];if ((typeof item == 'object') && item.url) {item.url.includes("http") || item.url.includes(";base64,") ? newArr.push(item.url) : newArr.push(process.env.VUE_APP_FILE_URL + item.url)} else {item.includes("http") || item.includes(";base64,") ? newArr.push(item) : newArr.push(process.env.VUE_APP_FILE_URL + item)}}return newArr},tabClick(tab, event) {const that = this;if (tab.name == 'video') {that.videoList.length > 0 ? that.$refs.videoCarousel.setActiveItem(0) : null;that.player = []that.autoPlayVideo(0)}},//设置播放点,续播autoPlayVideo(index, oldVal) {const that = this;let currVideo = document.getElementById(`video-${index}`);if (currVideo == null) { return }if (that.player.includes(currVideo)) {that.player[index].currentTime = 0, that.player[index].muted = false, that.player[index].autoplay = true, that.player[index].play().catch((err) => { });that.player[oldVal].currentTime = 0, that.player[oldVal].muted = true, that.player[oldVal].autoplay = false, that.player[oldVal].pause();} else {currVideo.currentTime = 0;//设置播放点currVideo.muted = false;//设置非静音that.sleep(100).then(() => {currVideo.play().catch((err) => { })that.player.includes(currVideo) ? null : that.player.push(currVideo);that.player.forEach((item, i) => { if (i != index) { item.autoplay = false, item.pause() } })that.player[index].addEventListener('ended', function (e) { //结束console.log("播放结束", e.target.id, that.player)that.$refs.videoCarousel.next()}, false);})}},},beforeDestroy() {this.videoList = []             //视频列表this.player = []},
}
</script>
三、遇到的问题:
【1】问题:el-carousel页面的视频不更新

文章链接:【vue】element强制刷新el-carousel的dom:

在这里插入图片描述

【2】问题:多按几次左按钮,其中跳过没有播放的视频没有销毁,造成再次自动播放时会跳页

将video存放到player里面,并修改video的播放状态
在这里插入图片描述

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

手机爬虫用Scrapy详细教程:构建高效的网络爬虫

如果你正在进行手机爬虫的工作&#xff0c;并且希望通过一个高效而灵活的框架来进行数据抓取&#xff0c;那么Scrapy将会是你的理想选择。Scrapy是一个强大的Python框架&#xff0c;专门用于构建网络爬虫。今天&#xff0c;我将与大家分享一份关于使用Scrapy进行手机爬虫的详细…

照片后期编辑工具Lightroom Classic 2024 mac中文新增功能

Lightroom Classic 2024&#xff08;lrC2024&#xff09;是专为摄影爱好者和专业摄影师设计的软件&#xff0c;它提供了全面的照片编辑工具&#xff0c;可以精准调整照片的色彩、对比度和曝光等参数&#xff0c;以便定制后期处理效果。 在lrC2024中&#xff0c;用户体验得到了提…

文件的逻辑结构(顺序文件,索引文件)

所谓的“逻辑结构”&#xff0c;就是指在用户看来&#xff0c;文件内部的数据应该是如何组织起来的。 而“物理结构”指的是在操作系统看来&#xff0c;文件的数据是如何存放在外存中的。 1.无结构文件 无结构文件:文件内部的数据就是一系列二进制流或字符流组成。无明显的逻…

SortedSet 和 List 异同点

SortedSet 在 Java 的整个集合体系中&#xff0c;集合可以分成两个体系&#xff0c;一个是 Collection 存储单个对象的集合&#xff0c;另一个是 k-v 结构的 Map 集合。 SortedSet 是 Collection 体系下 Set 接口下的派生类&#xff0c;而 Set 集合的特征是不包含重 复的元素的…

Linux screen命令解决SSH远程服务器训练代码断开连接后运行中断

Linux screen命令解决SSH远程服务器训练代码断开连接后运行中断_linux screen ssh-CSDN博客 xshell远程连接服务器&#xff0c;screen指令进行后台任务运行_xshell创建screen-CSDN博客

pytest合集(11)— conftest.py文件

1、conftest.py文件 conftest.py文件是pytest框架中的一个特殊文件&#xff0c;用于定义共享的设置、夹具(fixture)和钩子函数&#xff08;hook&#xff09;。 在pytest中&#xff0c;conftest.py文件可以用于在整个测试项目中共享夹具、配置和钩子函数。通过在conftest.py文…

(论文翻译)UFO: Unified Feature Optimization——UFO:统一特性优化

作者&#xff1a; Teng Xi 论文总结&#xff1a;总结 Code: https://github.com/PaddlePaddle/VIMER/tree/main/UFO 摘要&#xff1a; 本文提出了一种新的统一特征优化(Unified Feature Optimization, UFO)范式&#xff0c;用于在现实世界和大规模场景下训练和部署深度模型…

迭代器-面试

迭代器-面试 Object.prototype[Symbol.iterator] function () {return Object.values(this)[Symbol.iterator](); };var [a, b] { a: 1, b: 2 };console.log(a, b);解释 Object.prototype[Symbol.iterator] function () {return Object.values(this)[Symbol.iterator](); …

新媒体运营的营销方案

一、目标客户群体 新媒体运营是通过社交媒体、短视频、直播等方式将信息快速传播出去&#xff0c;因此&#xff0c;适合的目标客户群体应该是年轻人群体&#xff0c;包括大学生、职场青年、年轻家庭等。 二、营销策略 1、社交媒体营销策略 借助社交媒体平台&#xff0c;建立企…

asp.net特色商品购物网站系统VS开发sqlserver数据库web结构c#编程Microsoft Visual Studio

一、源码特点 asp.net特色商品购物网站系统 是一套完善的web设计管理系统&#xff0c;系统采用mvc模式&#xff08;BLLDALENTITY&#xff09;系统具有完整的源代码和数据库&#xff0c;系统主要采用B/S模式开发。开发环境为 vs2010&#xff0c;数据库为sqlserver2008&a…

安装Apache2.4

二、安装配置Apache&#xff1a; 中文官网&#xff1a;Apache 中文网 官网 (p2hp.com) 我下的是图中那个版本&#xff0c;最新的64位 下载下后解压缩。如解压到D:\tool\Apache24 PS&#xff1a;特别要注意使用的场景和64位还是32位版本 2、修改Apcahe配置文件 具体步骤: 打…

利用ZipInputStream(解压)/ZipOutputStream(压缩)文件夹

在操作.zip的压缩包时&#xff0c;可以用到高级流ZipInputStream和ZipOutputStream。.zip文件中的每个文件夹和文件都是一个ZipEntry对象。解压和压缩的本质就是操作每个ZipEntry对象&#xff0c;只能操作后缀为.zip的文件 1 解压.zip文件 ZipInputStream&#xff0c;解压。是…

Required MultipartFile parameter ‘file‘ is not present

出现这个原因我们首先想到的是加一个RequestParam("file")&#xff0c;但是还有可能的原因是因为我们的名字有错误 <span class"input-group-addon must">模板上传 </span> <input id"uploadFileUpdate" name"importFileU…

内衣专用洗衣机怎么样?选购内衣裤洗衣机的方法

有的小伙伴在问内衣洗衣机有没有必要入手&#xff0c;答案是有必要的&#xff0c;贴身衣物一定要和普通衣服分开来洗&#xff0c;而且用手来清洗衣物真的很耗时间而且还清洗不干净&#xff0c;有了内衣洗衣机&#xff0c;我们不仅可以解放双手&#xff0c;在清洗过程中还能更加…

安装Python没有pip python3.8为啥没安装pip

以管理员打开&#xff0c;很&#xff01;重&#xff01;要&#xff01; 进入存储路径: (获取存储路径的方法&#xff1a;在python中 import sys sys.path ) 1,cd C:\Python38\Scripts\dist\pip-23.3 python下安装pip: python setup.py install 回车后&#xff0c;安装开始运行…

实现日期间的运算——C++

&#x1f636;‍&#x1f32b;️Take your time ! &#x1f636;‍&#x1f32b;️ &#x1f4a5;个人主页&#xff1a;&#x1f525;&#x1f525;&#x1f525;大魔王&#x1f525;&#x1f525;&#x1f525; &#x1f4a5;代码仓库&#xff1a;&#x1f525;&#x1f525;魔…

SLAM 14 notes

4.23 推导 f ( x ) f(x) f(x)在点a处的泰勒展开 f ( x ) ∑ n 0 ∞ f ( n ) a n ! ( x − a ) n f(x) \sum_{n0}^\infty \frac{f^{(n)}a}{n!}(x-a)^n f(x)∑n0∞​n!f(n)a​(x−a)n l n x lnx lnx的n阶导数 l n ( n ) x ( − 1 ) n − 1 ( n − 1 ) ! x n ln^{(n)}x \fr…

Qt文件系统模型

创建文件系统模型&#xff1a;QFileSystemModel* model new QFileSystemModel(this); 设置根目录&#xff1a;model->setRootPath(QDir::currentPath()); 为视图设置模型&#xff1a; ui.treeView->setModel(model);ui.listView->setModel(model);ui.tableView-&g…

react 中获取多个input输入框中的值的 俩种写法

目录 1. 使用受控组件 2. 使用非受控组件 1. 使用受控组件 这是React中最常见的方法&#xff0c;每个输入框都与React组件的state相关联&#xff0c;并通过onChange事件来更新state。 代码示例&#xff1a; import React, { Component } from react;class MultipleInputExam…

TCP ZeroWindow 问题

TCP Zero Window问题是指在TCP连接中&#xff0c;发送方为了保障可靠传输&#xff0c;会根据接收方反馈的窗口大小来控制发送窗口的大小&#xff0c;但当接收方窗口大小为0时&#xff0c;发送方就会停止发送&#xff0c;从而导致通讯中断的问题。下面我们将从多个方面详细阐述T…