当前位置: 首页 > news >正文

【js】js实现多个视频连续播放:

文章目录

        • 一、效果:
        • 二、实现:
        • 三、案例:


一、效果:

image.png

二、实现:
<!DOCTYPE html>
<html>
<head><title>Video Player</title><style>#progressBar {   width: 800px;height: 20px;background-color: #ddd;}#progress {height: 20px;background-color: #abc;}#videoContainer {position: relative;width: 800px; height: 450px; /* adjust as needed */}#videoContainer video {position: absolute;width: 100%;height: 100%;}</style>
</head>
<body><div id="videoContainer"></div><button id="playButton">播放</button><button id="pauseButton">暂停</button><div id="progressBar"><div id="progress"></div></div><div>Total duration: <span id="totalDuration">0</span> seconds</div><div>Current time: <span id="currentTime">0</span> seconds</div><script>var videoContainer = document.getElementById('videoContainer');var videoSources = ["f1.mp4", "f2.mp4", "f3.mp4", "f4.mp4"];var totalDuration = 0;var totalCurrentTime = 0;var currentVideo = 0;var videoElements = videoSources.map(function (src, i) {var video = document.createElement('video');video.src = src;video.addEventListener('loadedmetadata', function  () {if (i < videoSources.length - 1) {videoElements[i + 1].load();}});video.addEventListener('play', function () {totalDuration = videoElements.reduce(function (sum, video) {return sum + (video.duration || 0);}, 0); document.getElementById('totalDuration').textContent = totalDuration;totalCurrentTime = videoElements.slice(0, i).reduce(function (sum, video) {return sum + (video.duration || 0);}, 0);document.getElementById('currentTime').textContent = totalCurrentTime;});if (i > 0) {video.style.display  = 'none';}videoContainer.appendChild(video);return video;});videoElements[0].load();videoElements.forEach(function (videoElement, i) {videoElement.addEventListener('timeupdate', function () {totalCurrentTime = videoElement.currentTime;for (var j =  0; j < i; j++) {totalCurrentTime += videoElements[j].duration;}document.getElementById('currentTime').textContent = totalCurrentTime;var progress = totalCurrentTime / totalDuration * 100;document.getElementById('progress').style.width = progress + '%';}, false);videoElement.addEventListener('ended', function () {currentVideo++;if (currentVideo < videoSources.length) {videoElements[currentVideo].play();videoElement.style.display = 'none';videoElements[currentVideo].style.display = 'block';}}, false);});document.getElementById('playButton').addEventListener('click', function () {videoElements[currentVideo].play();}, false);document.getElementById('pauseButton').addEventListener('click', function () {videoElements[currentVideo].pause();}, false);</script>
</body>
</html> 
三、案例:

image.png
image.png
image.png
image.png
image.png
image.png

http://www.lryc.cn/news/274875.html

相关文章:

  • 使用openssl 生成pfx格式证书时报错:unable to load certificates
  • 微信小程序 分享按钮 监听用户分享成功
  • 数据结构-怀化学院期末题
  • 跟cherno手搓游戏引擎【1】:配置与入口点
  • 25计算机专业考研经验贴之准备篇
  • 机器人相关知识
  • 八股文打卡day22——操作系统(5)
  • SQL Server 权限管理
  • ReentrantLock底层原理学习一
  • 数字孪生在增强现实(AR)中的应用
  • 【数据仓库与联机分析处理】多维数据模型
  • 【网络面试(3)】浏览器委托协议栈完成消息的收发
  • Kotlin: Jetpack — ViewModel简单应用
  • 【Java技术专题】「攻破技术盲区」攻破Java技术盲点之unsafe类的使用指南(打破Java的安全管控— sun.misc.unsafe)
  • 私有云平台搭建openstack和ceph结合搭建手册
  • debug mccl 02 —— 环境搭建及初步调试
  • ros python 接收GPS RTK 串口消息再转发 ros 主题消息
  • 2024年网络安全竞赛-页面信息发现任务解析
  • ARM DMA使用整理
  • 移动通信原理与关键技术学习(第四代蜂窝移动通信系统)
  • 光明源@智慧厕所技术:优化生活,提升卫生舒适度
  • 【Bootstrap学习 day13】
  • Shell:常用命令之dirname与basename
  • Linux-v4l2框架
  • VPC网络架构下的网络上数据采集
  • 模拟算法(模拟算法 == 依葫芦画瓢)万字
  • QtApplets-SystemInfo
  • vue3防抖函数封装与使用,以指令的形式使用
  • Hive学习(13)lag和lead函数取偏移量
  • Centos Unable to verify the graphical display setup