Fixes the "play next" bug and displaying another song then actually currently playing. Fixes #44

This commit is contained in:
Karim Abou Zeid 2015-08-21 21:24:32 +02:00
commit b5a0ae7a47
2 changed files with 25 additions and 18 deletions

View file

@ -28,6 +28,10 @@
<h3>Version 0.9.43 beta7</h3> <h3>Version 0.9.43 beta7</h3>
<ol> <ol>
<li><b>FIX:</b> "Play next" not always working.</a>.
</li>
<li><b>FIX:</b> Display another song then actually playing.</a>.
</li>
<li><b>FIX:</b> Updated strings to better follow the Material Design "writing" guidelines.</a>. <li><b>FIX:</b> Updated strings to better follow the Material Design "writing" guidelines.</a>.
</li> </li>
</ol> </ol>

View file

@ -55,6 +55,8 @@ import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import hugo.weaving.DebugLog;
/** /**
* @author Karim Abou Zeid (kabouzeid), Andrew Neal * @author Karim Abou Zeid (kabouzeid), Andrew Neal
*/ */
@ -75,6 +77,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
// do not change this strings as it will break support with other apps (e.g. last.fm scrobbling) // do not change this strings as it will break support with other apps (e.g. last.fm scrobbling)
public static final String META_CHANGED = "com.kabouzeid.gramophone.metachanged"; public static final String META_CHANGED = "com.kabouzeid.gramophone.metachanged";
public static final String QUEUE_CHANGED = "com.kabouzeid.gramophone.queuechanged";
public static final String PLAY_STATE_CHANGED = "com.kabouzeid.gramophone.playstatechanged"; public static final String PLAY_STATE_CHANGED = "com.kabouzeid.gramophone.playstatechanged";
public static final String REPEAT_MODE_CHANGED = "com.kabouzeid.gramophone.repeatmodechanged"; public static final String REPEAT_MODE_CHANGED = "com.kabouzeid.gramophone.repeatmodechanged";
public static final String SHUFFLE_MODE_CHANGED = "com.kabouzeid.gramophone.shufflemodechanged"; public static final String SHUFFLE_MODE_CHANGED = "com.kabouzeid.gramophone.shufflemodechanged";
@ -395,6 +398,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
} }
} }
@DebugLog
private boolean prepareNext() { private boolean prepareNext() {
synchronized (this) { synchronized (this) {
try { try {
@ -566,7 +570,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
if (startPlaying) { if (startPlaying) {
playSongAt(position); playSongAt(position);
} }
saveState(); notifyChange(QUEUE_CHANGED);
} }
} }
@ -588,6 +592,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
notHandledMetaChangedForCurrentTrack = true; notHandledMetaChangedForCurrentTrack = true;
sendChangeIntent(META_CHANGED); sendChangeIntent(META_CHANGED);
sendChangeIntent(QUEUE_CHANGED);
updateWidgets(); updateWidgets();
} }
} }
@ -595,19 +600,19 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
public void addSong(int position, Song song) { public void addSong(int position, Song song) {
playingQueue.add(position, song); playingQueue.add(position, song);
originalPlayingQueue.add(position, song); originalPlayingQueue.add(position, song);
saveState(); notifyChange(QUEUE_CHANGED);
} }
public void addSong(Song song) { public void addSong(Song song) {
playingQueue.add(song); playingQueue.add(song);
originalPlayingQueue.add(song); originalPlayingQueue.add(song);
saveState(); notifyChange(QUEUE_CHANGED);
} }
public void addSongs(List<Song> songs) { public void addSongs(List<Song> songs) {
playingQueue.addAll(songs); playingQueue.addAll(songs);
originalPlayingQueue.addAll(songs); originalPlayingQueue.addAll(songs);
saveState(); notifyChange(QUEUE_CHANGED);
} }
public void removeSong(int position) { public void removeSong(int position) {
@ -617,7 +622,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
} else { } else {
originalPlayingQueue.remove(playingQueue.remove(position)); originalPlayingQueue.remove(playingQueue.remove(position));
} }
saveState(); notifyChange(QUEUE_CHANGED);
} }
public void removeSong(@NonNull Song song) { public void removeSong(@NonNull Song song) {
@ -627,7 +632,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
for (int i = 0; i < originalPlayingQueue.size(); i++) { for (int i = 0; i < originalPlayingQueue.size(); i++) {
if (originalPlayingQueue.get(i).id == song.id) originalPlayingQueue.remove(i); if (originalPlayingQueue.get(i).id == song.id) originalPlayingQueue.remove(i);
} }
saveState(); notifyChange(QUEUE_CHANGED);
} }
public void moveSong(int from, int to) { public void moveSong(int from, int to) {
@ -645,8 +650,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
} else if (from == currentPosition) { } else if (from == currentPosition) {
setPosition(to); setPosition(to);
} }
if (from != to) prepareNext(); notifyChange(QUEUE_CHANGED);
saveState();
} }
public void playSongAt(final int position) { public void playSongAt(final int position) {
@ -795,8 +799,8 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
setPosition(newPosition); setPosition(newPosition);
break; break;
} }
prepareNext();
notifyChange(SHUFFLE_MODE_CHANGED); notifyChange(SHUFFLE_MODE_CHANGED);
notifyChange(QUEUE_CHANGED);
} }
private void notifyChange(@NonNull final String what) { private void notifyChange(@NonNull final String what) {
@ -842,6 +846,9 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
final Song currentSong = getCurrentSong(); final Song currentSong = getCurrentSong();
recentlyPlayedStore.addSongId(currentSong.id); recentlyPlayedStore.addSongId(currentSong.id);
songPlayCountStore.bumpSongCount(currentSong.id); songPlayCountStore.bumpSongCount(currentSong.id);
} else if (what.equals(QUEUE_CHANGED)) {
saveState();
prepareNext();
} }
} }
@ -859,19 +866,15 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
wakeLock.acquire(milli); wakeLock.acquire(milli);
} }
private void setGaplessPlaybackEnabled(boolean setEnabled) {
if (setEnabled) {
prepareNext();
} else {
player.setNextDataSource(null);
}
}
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
switch (key) { switch (key) {
case PreferenceUtil.GAPLESS_PLAYBACK: case PreferenceUtil.GAPLESS_PLAYBACK:
setGaplessPlaybackEnabled(sharedPreferences.getBoolean(key, false)); if (sharedPreferences.getBoolean(key, false)) {
prepareNext();
} else {
player.setNextDataSource(null);
}
break; break;
case PreferenceUtil.ALBUM_ART_ON_LOCKSCREEN: case PreferenceUtil.ALBUM_ART_ON_LOCKSCREEN:
updateRemoteControlClientImpl(sharedPreferences.getBoolean(key, true)); updateRemoteControlClientImpl(sharedPreferences.getBoolean(key, true));