SimpleMobileTools / Simple-Music-Player

A clean music player with a customizable widget, stylish interface and no ads.
https://www.simplemobiletools.com
GNU General Public License v3.0
1.28k stars 405 forks source link

Add support for gapless playback #522

Closed naveensingh closed 1 year ago

naveensingh commented 1 year ago

This PR addresses https://github.com/SimpleMobileTools/Simple-Music-Player/issues/326

As can be seen here, there are many ways to implement gapless playback but this implementation relies completely on MediaPlayer.setNextMediaPlayer() method:

 * Set the MediaPlayer to start when this MediaPlayer finishes playback
 * (i.e. reaches the end of the stream).
 * The media framework will attempt to transition from this player to
 * the next as seamlessly as possible. The next player can be set at
 * any time before completion, but shall be after setDataSource has been
 * called successfully. 

It works on all the devices I could find and create but some devices may have a problem with it and that is why I have disabled gapless playback by default.

Major change: Added a helper media player wrapper class that manages audio focus and gapless playback (based on other open-source players). It can be generalized further to later add support for crossfade.

Testing: I tested on multiple devices, versions, and files, and nothing is broken. To test gapless playback, you can use this file. It contains a song split into multiple parts. The player should move from one part to the next seamlessly when gapless playback is on.

I will keep testing it out for any other issues...

tibbi commented 1 year ago

yeah nice, seems to work well