clean up playback interface and a few other classes
This commit is contained in:
parent
cf03b05809
commit
7edf0c85fa
12 changed files with 50 additions and 242 deletions
|
|
@ -46,7 +46,6 @@ public class MultiPlayer implements Playback {
|
|||
private boolean isReady = false;
|
||||
private boolean isPlaying = false;
|
||||
private boolean isNew = false;
|
||||
private boolean isFirst = true;
|
||||
|
||||
private ExoPlayer.EventListener eventListener = new ExoPlayer.EventListener() {
|
||||
@Override
|
||||
|
|
@ -118,7 +117,7 @@ public class MultiPlayer implements Playback {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setNextDataSource(@Nullable final String path) {
|
||||
public void queueDataSource(@Nullable final String path) {
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -151,11 +150,7 @@ public class MultiPlayer implements Playback {
|
|||
}
|
||||
|
||||
mediaSource.addMediaSource(source);
|
||||
if (!isFirst && next) {
|
||||
start();
|
||||
}
|
||||
|
||||
isFirst = false;
|
||||
if (next) start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -171,7 +166,7 @@ public class MultiPlayer implements Playback {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
public void start() {
|
||||
isPlaying = true;
|
||||
exoPlayer.setPlayWhenReady(true);
|
||||
|
||||
|
|
@ -179,8 +174,6 @@ public class MultiPlayer implements Playback {
|
|||
callbacks.onTrackStarted();
|
||||
isNew = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -190,10 +183,9 @@ public class MultiPlayer implements Playback {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean pause() {
|
||||
public void pause() {
|
||||
isPlaying = false;
|
||||
exoPlayer.setPlayWhenReady(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -220,8 +212,7 @@ public class MultiPlayer implements Playback {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean setVolume(float volume) {
|
||||
public void setVolume(float volume) {
|
||||
exoPlayer.setVolume(volume);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,6 +218,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
if (audioManager == null) {
|
||||
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
||||
}
|
||||
|
||||
return audioManager;
|
||||
}
|
||||
|
||||
|
|
@ -422,7 +423,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
this.playingQueue = restoredQueue;
|
||||
|
||||
position = restoredPosition;
|
||||
openCurrent();
|
||||
openCurrent(true);
|
||||
|
||||
if (restoredPositionInTrack > 0) seek(restoredPositionInTrack);
|
||||
|
||||
|
|
@ -471,18 +472,25 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
synchronized (this) {
|
||||
this.position = position;
|
||||
|
||||
openCurrent();
|
||||
openCurrent(false);
|
||||
|
||||
notifyChange(META_CHANGED);
|
||||
notHandledMetaChangedForCurrentTrack = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void openCurrent() {
|
||||
private void openCurrent(boolean queue) {
|
||||
synchronized (this) {
|
||||
// current song will be null when queue is cleared
|
||||
if (getCurrentSong() == null) return;
|
||||
playback.setDataSource(getTrackUri(getCurrentSong()));
|
||||
|
||||
if (queue) {
|
||||
// restore queue from database
|
||||
playback.queueDataSource(getTrackUri(getCurrentSong()));
|
||||
} else {
|
||||
// set current song and start playback
|
||||
playback.setDataSource(getTrackUri(getCurrentSong()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -494,7 +502,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
private void prepareNextImpl() {
|
||||
synchronized (this) {
|
||||
nextPosition = getNextPosition(false);
|
||||
playback.setNextDataSource(getTrackUri(getSongAt(nextPosition)));
|
||||
playback.queueDataSource(getTrackUri(getSongAt(nextPosition)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +1,29 @@
|
|||
package com.dkanada.gramophone.service.playback;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public interface Playback {
|
||||
void setDataSource(String path);
|
||||
|
||||
void setNextDataSource(@Nullable String path);
|
||||
void queueDataSource(String path);
|
||||
|
||||
void setCallbacks(PlaybackCallbacks callbacks);
|
||||
|
||||
boolean isInitialized();
|
||||
void start();
|
||||
|
||||
boolean start();
|
||||
void pause();
|
||||
|
||||
void stop();
|
||||
|
||||
boolean pause();
|
||||
boolean isInitialized();
|
||||
|
||||
boolean isPlaying();
|
||||
|
||||
int duration();
|
||||
|
||||
int position();
|
||||
|
||||
int seek(int whereto);
|
||||
int duration();
|
||||
|
||||
boolean setVolume(float vol);
|
||||
int seek(int position);
|
||||
|
||||
void setVolume(float volume);
|
||||
|
||||
interface PlaybackCallbacks {
|
||||
void onTrackStarted();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue