Java Code Examples for android.media.session.PlaybackState#PLAYBACK_POSITION_UNKNOWN

The following examples show how to use android.media.session.PlaybackState#PLAYBACK_POSITION_UNKNOWN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicBrowserService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updatePlaybackState(String error) {
    long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN;
    MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject();
    if (playingMessageObject != null) {
        position = playingMessageObject.audioProgressSec * 1000;
    }

    PlaybackState.Builder stateBuilder = new PlaybackState.Builder().setActions(getAvailableActions());
    int state;
    if (playingMessageObject == null) {
        state = PlaybackState.STATE_STOPPED;
    } else {
        if (MediaController.getInstance().isDownloadingCurrentMessage()) {
            state = PlaybackState.STATE_BUFFERING;
        } else {
            state = MediaController.getInstance().isMessagePaused() ? PlaybackState.STATE_PAUSED : PlaybackState.STATE_PLAYING;
        }
    }

    if (error != null) {
        stateBuilder.setErrorMessage(error);
        state = PlaybackState.STATE_ERROR;
    }
    stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime());
    if (playingMessageObject != null) {
        stateBuilder.setActiveQueueItemId(MediaController.getInstance().getPlayingMessageObjectNum());
    } else {
        stateBuilder.setActiveQueueItemId(0);
    }

    mediaSession.setPlaybackState(stateBuilder.build());
}
 
Example 2
Source File: MusicBrowserService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updatePlaybackState(String error) {
    long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN;
    MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject();
    if (playingMessageObject != null) {
        position = playingMessageObject.audioProgressSec * 1000;
    }

    PlaybackState.Builder stateBuilder = new PlaybackState.Builder().setActions(getAvailableActions());
    int state;
    if (playingMessageObject == null) {
        state = PlaybackState.STATE_STOPPED;
    } else {
        if (MediaController.getInstance().isDownloadingCurrentMessage()) {
            state = PlaybackState.STATE_BUFFERING;
        } else {
            state = MediaController.getInstance().isMessagePaused() ? PlaybackState.STATE_PAUSED : PlaybackState.STATE_PLAYING;
        }
    }

    if (error != null) {
        stateBuilder.setErrorMessage(error);
        state = PlaybackState.STATE_ERROR;
    }
    stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime());
    if (playingMessageObject != null) {
        stateBuilder.setActiveQueueItemId(MediaController.getInstance().getPlayingMessageObjectNum());
    } else {
        stateBuilder.setActiveQueueItemId(0);
    }

    mediaSession.setPlaybackState(stateBuilder.build());
}
 
Example 3
Source File: MediaServiceHandler.java    From Aerlink-for-Android with MIT License 5 votes vote down vote up
private void updatePlaybackState() {
    long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN;
    PlaybackState.Builder stateBuilder = new PlaybackState.Builder()
            .setActions(PlaybackState.ACTION_PLAY_PAUSE
                    | PlaybackState.ACTION_SKIP_TO_PREVIOUS
                    | PlaybackState.ACTION_SKIP_TO_NEXT);
    stateBuilder.setState(mediaPlaying ? PlaybackState.STATE_PLAYING : PlaybackState.STATE_PAUSED, position, 1.0f);
    mSession.setPlaybackState(stateBuilder.build());
}
 
Example 4
Source File: MusicBrowserService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void updatePlaybackState(String error) {
    long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN;
    MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject();
    if (playingMessageObject != null) {
        position = playingMessageObject.audioProgressSec * 1000L;
    }

    PlaybackState.Builder stateBuilder = new PlaybackState.Builder().setActions(getAvailableActions());
    int state;
    if (playingMessageObject == null) {
        state = PlaybackState.STATE_STOPPED;
    } else {
        if (MediaController.getInstance().isDownloadingCurrentMessage()) {
            state = PlaybackState.STATE_BUFFERING;
        } else {
            state = MediaController.getInstance().isMessagePaused() ? PlaybackState.STATE_PAUSED : PlaybackState.STATE_PLAYING;
        }
    }

    if (error != null) {
        stateBuilder.setErrorMessage(error);
        state = PlaybackState.STATE_ERROR;
    }
    stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime());
    if (playingMessageObject != null) {
        stateBuilder.setActiveQueueItemId(MediaController.getInstance().getPlayingMessageObjectNum());
    } else {
        stateBuilder.setActiveQueueItemId(0);
    }

    mediaSession.setPlaybackState(stateBuilder.build());
}
 
Example 5
Source File: MusicBrowserService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void updatePlaybackState(String error) {
    long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN;
    MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject();
    if (playingMessageObject != null) {
        position = playingMessageObject.audioProgressSec * 1000L;
    }

    PlaybackState.Builder stateBuilder = new PlaybackState.Builder().setActions(getAvailableActions());
    int state;
    if (playingMessageObject == null) {
        state = PlaybackState.STATE_STOPPED;
    } else {
        if (MediaController.getInstance().isDownloadingCurrentMessage()) {
            state = PlaybackState.STATE_BUFFERING;
        } else {
            state = MediaController.getInstance().isMessagePaused() ? PlaybackState.STATE_PAUSED : PlaybackState.STATE_PLAYING;
        }
    }

    if (error != null) {
        stateBuilder.setErrorMessage(error);
        state = PlaybackState.STATE_ERROR;
    }
    stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime());
    if (playingMessageObject != null) {
        stateBuilder.setActiveQueueItemId(MediaController.getInstance().getPlayingMessageObjectNum());
    } else {
        stateBuilder.setActiveQueueItemId(0);
    }

    mediaSession.setPlaybackState(stateBuilder.build());
}