Sync multiple HTML5 audio tracks with seek

余生长醉 提交于 2020-01-01 16:49:08

问题


I'm trying to play multiple audio files at the same time, and keep them all in sync. However, if I seek forward in the song by pausing and setting the currentTime, the audio becomes out of sync. The currentTime properties are all equal, yet the sound is drastically out of sync.

I have also tried using a MediaController on all the tracks, which also didn't work.

Anyone know how to keep multiple tracks in sync after a seek?


回答1:


If you're trying to use elements to synchronize, you'll never quite manage to get them to sync. The api just isn't designed to handle precise timing. The best way to precisely sync audio buffers is to use the Web Audio API (https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html); you can then precisely schedule start() calls on multiple audio buffers at the same time, and they will be locked in step.

Relying on streaming and expecting synchronization is a recipe for disappointment. :)



来源:https://stackoverflow.com/questions/16489495/sync-multiple-html5-audio-tracks-with-seek

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!