I have web based audio player and want to preload next track while current is playing.
So I create new audio object prefetch = new Audio(url)
and when it is time to switch I just swap current audio with preloaded one and trigger .play()
.
But it doesn't always work when tab is not active. Sometimes when it is time to swap I found prefetched object with networkState == 3 (NETWORK_NO_SOURCE)
and readyState = 0 (HAVE_NOTHING)
.
When I switch back to the tab - it immediately starts to playing.
I beleive it caused by async resource selection algorithm and browser optmiziations, but not sure how to make it work.
(Mostly reproducible in Safari).