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,8 +497,7 @@ 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();
@ -507,29 +506,24 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
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() {
playerHandler.removeMessages(PREPARE_NEXT); playerHandler.removeMessages(PREPARE_NEXT);
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() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && !PreferenceUtil.getInstance(this).getClassicNotification()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && !PreferenceUtil.getInstance(this).getClassicNotification()) {
@ -656,8 +650,7 @@ 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);
@ -672,7 +665,6 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
} }
} }
} }
}
public void playPreviousSong(boolean force) { public void playPreviousSong(boolean force) {
playSongAt(queueManager.getPreviousPosition(force)); playSongAt(queueManager.getPreviousPosition(force));
@ -694,13 +686,11 @@ 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) {
handleChangeInternal(what); handleChangeInternal(what);