Search in sources :

Example 1 with PlayerState

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();
        }
    });
}
Also used : Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) DownloadFile(org.moire.ultrasonic.service.DownloadFile) PlayerState(org.moire.ultrasonic.domain.PlayerState) SilentBackgroundTask(org.moire.ultrasonic.util.SilentBackgroundTask) DownloadService(org.moire.ultrasonic.service.DownloadService)

Example 2 with PlayerState

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();
}
Also used : PlayerState(org.moire.ultrasonic.domain.PlayerState) DownloadService(org.moire.ultrasonic.service.DownloadService) Point(android.graphics.Point)

Example 3 with PlayerState

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);
        }
    }
}
Also used : PlayerState(org.moire.ultrasonic.domain.PlayerState) DownloadService(org.moire.ultrasonic.service.DownloadService)

Aggregations

PlayerState (org.moire.ultrasonic.domain.PlayerState)3 DownloadService (org.moire.ultrasonic.service.DownloadService)3 Point (android.graphics.Point)1 Entry (org.moire.ultrasonic.domain.MusicDirectory.Entry)1 DownloadFile (org.moire.ultrasonic.service.DownloadFile)1 SilentBackgroundTask (org.moire.ultrasonic.util.SilentBackgroundTask)1