try 循环播放预告片,直到用户单击屏幕上的某个位置,然后应播放一次讲座视频,然后恢复到预告片.

我做错了什么?

<video id="mp4Source" autoplay loop controls width="100%" src="/assets/trailer.mp4" >

</video>

<button type="button" name="button" onclick="playLectureVid()"> Play Lecture Vid</button>

function playLectureVid(){
    var video =  document.getElementById("mp4Source");
    video.src = '/assets/lecture.mp4';
    video.load();
    video.play();
    video.addEventListener("ended", function(e) {
      e.currentTarget.removeEventListener(e.type, handler);
      video.src = '/assets/trailer.mp4';
      video.load();
      video.play();
    });
  }

推荐答案

只需在两个视频之间切换即可.

var trailer = document.getElementById("trailer");
var lecture = document.getElementById("lecture");

function playLectureVid() {
  lecture.style.display = 'block';
  trailer.style.display = 'none';
  trailer.pause();
  lecture.play();
}

lecture.addEventListener("ended", function(e) {
  trailer.style.display = 'block';
  lecture.style.display = 'none';
  lecture.pause();
  trailer.play();
});
video {
  width: 400px;
}

#lecture {
  display: none;
}
<center>
  <button type="button" name="button" onclick="playLectureVid()"> Play Lecture Vid</button>
  <br>
  <video id="trailer" autoplay muted loop controls width="100%" src="https://jsoncompare.org/LearningContainer/SampleFiles/Video/MP4/Sample-MP4-Video-File-for-Testing.mp4"></video>
  <video id="lecture" controls width="100%" src="https://samplelib.com/lib/preview/mp4/sample-5s.mp4"></video>

</center>

Javascript相关问答推荐

如何才能拥有在jQuery终端中执行命令的链接?

传递一个大对象以在Express布局中呈现

网页自检测外部元素无法加载

Exceljs:我们在file.xlsx(...)&#中发现了一个问题'"" 39人;

当使用';字母而不是与';var#39;一起使用时,访问窗口为什么返回未定义的?

WP Bootstrap NavWaker:下拉菜单一次打开所有下拉菜单

背景动画让网站摇摇欲坠

Node.js API-queryAll()中的MarkLogic数据移动

未捕获的不变违规:即使在使用DndProvider之后也应使用拖放上下文

为什么我的Navbar.css没有显示在本地主机页面上?

为什么我的SoupRequest";被重置为初始值,以及如何修复它?

在高位图中显示每个y轴系列的多个值

每隔一行文本段落进行镜像(Boustrophedon)

使用onClick单击子元素时,使用交点观察器的关键帧动画意外运行

如何从图表中映射一组图表-js使用REACT

我正在为我的单选按钮在HTML中设置一个值.使用Java脚本,我如何才能获得该值?

如何将PNG图像放在wix站点的Open Streemap map 上,使PNG图像成为 map 不可分割的一部分?

如何使用Reaction/Redux创建购物车逻辑?

JQuery-无法 Select 使用elementor添加的元素的值

查找函数句柄的模块/文件