问题
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