use of org.moire.ultrasonic.domain.PlayerState in project ultrasonic by ultrasonic.
the class SubsonicTabActivity method showNowPlaying.
public void showNowPlaying() {
this.runOnUiThread(new Runnable() {
@Override
public void run() {
new SilentBackgroundTask<Void>(SubsonicTabActivity.this) {
@Override
protected Void doInBackground() throws Throwable {
if (!Util.getShowNowPlayingPreference(SubsonicTabActivity.this)) {
hideNowPlaying();
return null;
}
nowPlayingView = findViewById(R.id.now_playing);
if (nowPlayingView != null) {
final DownloadService downloadService = DownloadServiceImpl.getInstance();
if (downloadService != null) {
PlayerState playerState = downloadService.getPlayerState();
if (playerState.equals(PlayerState.PAUSED) || playerState.equals(PlayerState.STARTED)) {
DownloadFile file = downloadService.getCurrentPlaying();
if (file != null) {
final Entry song = file.getSong();
showNowPlaying(SubsonicTabActivity.this, downloadService, song, playerState);
}
} else {
hideNowPlaying();
}
}
}
return null;
}
@Override
protected void done(Void result) {
}
}.execute();
}
});
}
use of org.moire.ultrasonic.domain.PlayerState in project ultrasonic by ultrasonic.
the class DownloadActivity method onSliderProgressChanged.
private void onSliderProgressChanged() {
DownloadService downloadService = getDownloadService();
if (downloadService == null || onProgressChangedTask != null) {
return;
}
onProgressChangedTask = new SilentBackgroundTask<Void>(this) {
DownloadService downloadService;
boolean isJukeboxEnabled;
int millisPlayed;
Integer duration;
PlayerState playerState;
@Override
protected Void doInBackground() throws Throwable {
downloadService = getDownloadService();
isJukeboxEnabled = downloadService.isJukeboxEnabled();
millisPlayed = Math.max(0, downloadService.getPlayerPosition());
duration = downloadService.getPlayerDuration();
playerState = getDownloadService().getPlayerState();
return null;
}
@Override
protected void done(final Void result) {
if (currentPlaying != null) {
final int millisTotal = duration == null ? 0 : duration;
positionTextView.setText(Util.formatTotalDuration(millisPlayed, true));
durationTextView.setText(Util.formatTotalDuration(millisTotal, true));
// Work-around for apparent bug.
progressBar.setMax(millisTotal == 0 ? 100 : millisTotal);
progressBar.setProgress(millisPlayed);
progressBar.setEnabled(currentPlaying.isWorkDone() || isJukeboxEnabled);
} else {
positionTextView.setText(R.string.util_zero_time);
durationTextView.setText(R.string.util_no_time);
progressBar.setProgress(0);
progressBar.setMax(0);
progressBar.setEnabled(false);
}
switch(playerState) {
case DOWNLOADING:
final long bytes = currentPlaying != null ? currentPlaying.getPartialFile().length() : 0;
String downloadStatus = getResources().getString(R.string.download_playerstate_downloading, Util.formatLocalizedBytes(bytes, DownloadActivity.this));
setActionBarSubtitle(downloadStatus);
break;
case PREPARING:
setActionBarSubtitle(R.string.download_playerstate_buffering);
break;
case STARTED:
final DownloadService downloadService = getDownloadService();
if (downloadService != null && downloadService.isShufflePlayEnabled()) {
setActionBarSubtitle(R.string.download_playerstate_playing_shuffle);
} else {
setActionBarSubtitle(null);
}
break;
default:
setActionBarSubtitle(null);
break;
case IDLE:
break;
case PREPARED:
break;
case STOPPED:
break;
case PAUSED:
break;
case COMPLETED:
break;
}
switch(playerState) {
case STARTED:
pauseButton.setVisibility(View.VISIBLE);
stopButton.setVisibility(View.GONE);
startButton.setVisibility(View.GONE);
break;
case DOWNLOADING:
case PREPARING:
pauseButton.setVisibility(View.GONE);
stopButton.setVisibility(View.VISIBLE);
startButton.setVisibility(View.GONE);
break;
default:
pauseButton.setVisibility(View.GONE);
stopButton.setVisibility(View.GONE);
startButton.setVisibility(View.VISIBLE);
break;
}
onProgressChangedTask = null;
}
};
onProgressChangedTask.execute();
}
use of org.moire.ultrasonic.domain.PlayerState in project ultrasonic by ultrasonic.
the class DownloadActivity method start.
private void start() {
final DownloadService service = getDownloadService();
final PlayerState state = service.getPlayerState();
if (state == PAUSED || state == COMPLETED || state == STOPPED) {
service.start();
} else if (state == IDLE) {
warnIfNetworkOrStorageUnavailable();
final int current = service.getCurrentPlayingIndex();
if (current == -1) {
service.play(0);
} else {
service.play(current);
}
}
}
Aggregations