同步HTML5<视频>以<音频>回放 [英] Syncing HTML5 <video> with <audio> playback

查看:147
本文介绍了同步HTML5<视频>以<音频>回放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有轨道从一个源,静音,我想用元素播放背景音乐了它。曲目包含了一段时间的关键因素。

I am having track from one source, mute, and I'd like to play background music over it using element. The tracks contain some time critical elements.

什么是同步在HTML5 / JavaScript的这两种不同的媒体播放器的选项?会给主时钟,因为它的音频播放是非常敏感的时间 - 现在松动的视频帧,然后不是关键

What would be the options to sync these two different media players in HTML5 / Javascript? would give the master clock as it audio playback is very time sensitive - loosing video frames now and then is not critical.

推荐答案

米科Ohtamaa提供了一个评论,这我倒认为是最好的选择这里的解决方案 - 它不需要一个框架,它不需要您可以编辑您的视频文件。

Mikko Ohtamaa provided a solution in a comment, which I actually think is the best option here - it doesn't require a framework, and it doesn't require you to edit your video files.

从本质上讲,只要抓住当前时间从视频元素时它是静音,并应用到时候音频元素。有些code可能是这样的:

Essentially, just grab the current time from the video element when it is "unmuted", and apply that time to the audio element. Some code might look like this:

function unmute() {
  var vid = document.getElementById("video");
  var aud = document.getElementById("audio");

  aud.currentTime = vid.currentTime;
  aud.play();

}

这篇关于同步HTML5<视频>以<音频>回放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆