refactor: move synchronized keyword in funtion header

This commit is contained in:
Jakob Kukla 2021-11-15 23:53:13 +01:00
commit a429198833

View file

@ -497,24 +497,20 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
playSongAt(queueManager.getNextPosition(force)); playSongAt(queueManager.getNextPosition(force));
} }
private void openTrackAndPrepareNextAt(int position) { private synchronized void openTrackAndPrepareNextAt(int position) {
synchronized (this) { queueManager.position = position;
queueManager.position = position;
openCurrent(); openCurrent();
playback.start(); playback.start();
notifyChange(META_CHANGED); notifyChange(META_CHANGED);
notHandledMetaChangedForCurrentTrack = false; notHandledMetaChangedForCurrentTrack = false;
}
} }
private void openCurrent() { private synchronized void openCurrent() {
synchronized (this) { if (queueManager.getCurrentSong() == null) return;
if (queueManager.getCurrentSong() == null) return;
playback.setDataSource(queueManager.getCurrentSong()); playback.setDataSource(queueManager.getCurrentSong());
}
} }
private void prepareNext() { private void prepareNext() {
@ -522,13 +518,11 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
playerHandler.obtainMessage(PREPARE_NEXT).sendToTarget(); playerHandler.obtainMessage(PREPARE_NEXT).sendToTarget();
} }
private void prepareNextImpl() { private synchronized void prepareNextImpl() {
synchronized (this) { if (queueManager.getCurrentSong() == null) return;
if (queueManager.getCurrentSong() == null) return;
queueManager.nextPosition = queueManager.getNextPosition(false); queueManager.nextPosition = queueManager.getNextPosition(false);
playback.queueDataSource(queueManager.getSongAt(queueManager.nextPosition)); playback.queueDataSource(queueManager.getSongAt(queueManager.nextPosition));
}
} }
public void initNotification() { public void initNotification() {
@ -656,20 +650,18 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
} }
} }
public void play() { public synchronized void play() {
synchronized (this) { if (!playback.isPlaying()) {
if (!playback.isPlaying()) { if (!playback.isReady()) {
if (!playback.isReady()) { playSongAt(queueManager.position);
playSongAt(queueManager.position); } else {
} else { playback.start();
playback.start(); if (notHandledMetaChangedForCurrentTrack) {
if (notHandledMetaChangedForCurrentTrack) { handleChangeInternal(META_CHANGED);
handleChangeInternal(META_CHANGED); notHandledMetaChangedForCurrentTrack = false;
notHandledMetaChangedForCurrentTrack = false;
}
notifyChange(STATE_CHANGED);
} }
notifyChange(STATE_CHANGED);
} }
} }
} }
@ -694,12 +686,10 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
return playback.getDuration(); return playback.getDuration();
} }
public int seek(int millis) { public synchronized int seek(int millis) {
synchronized (this) { playback.setProgress(millis);
playback.setProgress(millis); throttledSeekHandler.notifySeek();
throttledSeekHandler.notifySeek(); return millis;
return millis;
}
} }
private void notifyChange(@NonNull final String what) { private void notifyChange(@NonNull final String what) {