Gapless playback with 2 media players is not possible, mostly because of unpredictable delay between entering pausedPlayer.start()
and actual playback. The delay can even be negative, because an unpaused player skips some milliseconds.
I tried to squeeze the most from 2 media players here: https://github.com/basinilya/piterfm/blob/7e1f62a2303d1a32f617eee629ab514bc6019437/src/ru/piter/fm/player/SmoothMediaPlayer.java
getCurrentPosition()
step on mp4 AAC fils is to rough: ~46 or ~92ms. So to get real position I wait in a loop until the value changes.- I don't call
seek(2000)
on next player, but instead warm it up by silencing and running for some time - When it's about time to switch to the next player, I get the precisest possible positions, then sleep, then resume the muted player, sleep again, and unmute it.
- time to sleep is calculated from both positions and average resume delay.
On real devices the clicks stay, but not so noticeable