Java Code Examples for android.support.v4.media.session.PlaybackStateCompat#REPEAT_MODE_ALL

The following examples show how to use android.support.v4.media.session.PlaybackStateCompat#REPEAT_MODE_ALL . 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: MusicPlayer.java    From Jockey with Apache License 2.0 6 votes vote down vote up
@Override
public void onSetRepeatMode(int repeatMode) {
    if (mMusicPlayer.isReleased()) return;

    switch (repeatMode) {
        case PlaybackStateCompat.REPEAT_MODE_ALL:
            mMusicPlayer.setRepeat(REPEAT_ALL);
            break;
        case PlaybackStateCompat.REPEAT_MODE_NONE:
            mMusicPlayer.setRepeat(REPEAT_NONE);
            break;
        case PlaybackStateCompat.REPEAT_MODE_ONE:
            mMusicPlayer.setRepeat(REPEAT_ONE);
            break;
    }
}
 
Example 2
Source File: PlayActivity.java    From blade-player with GNU General Public License v3.0 5 votes vote down vote up
public void onRepeatClicked(View v)
{
    int currentRepeatMode = musicPlayer.getRepeatMode();

    if(currentRepeatMode == PlaybackStateCompat.REPEAT_MODE_NONE) currentRepeatMode = PlaybackStateCompat.REPEAT_MODE_ONE;
    else if(currentRepeatMode == PlaybackStateCompat.REPEAT_MODE_ONE) currentRepeatMode = PlaybackStateCompat.REPEAT_MODE_ALL;
    else if(currentRepeatMode == PlaybackStateCompat.REPEAT_MODE_ALL) currentRepeatMode = PlaybackStateCompat.REPEAT_MODE_NONE;

    PlayerConnection.musicController.getTransportControls().setRepeatMode(currentRepeatMode);

    /* manually refresh UI */
    if(currentRepeatMode == PlaybackStateCompat.REPEAT_MODE_NONE) repeatAction.setImageResource(R.drawable.ic_action_repeat_white);
    else if(currentRepeatMode == PlaybackStateCompat.REPEAT_MODE_ONE) repeatAction.setImageResource(R.drawable.ic_action_repeat_one);
    else repeatAction.setImageResource(R.drawable.ic_action_repeat_enabled);
}
 
Example 3
Source File: PlayerService.java    From blade-player with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onStateChange()
{
    if(currentPlaylist == null) return;

    /* we reached song end ; go to new song */
    if(mPlayer.getCurrentState() == PlayerMediaPlayer.PLAYER_STATE_SONGEND)
    {
        if(repeatMode == PlaybackStateCompat.REPEAT_MODE_ONE)
        {
            mSessionCallback.onPlay();
        }
        else if((repeatMode == PlaybackStateCompat.REPEAT_MODE_ALL) || (currentPosition != currentPlaylist.size()-1))
        {
            mSessionCallback.onSkipToNext();
            return;
        }
        else mPlayer.setPlaylistEnded();
    }

    /* send current state to mediasession */

    //send PlaybackState
    mSession.setPlaybackState(mPlayer.getPlaybackState());

    //build and send current media informations
    MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
    Song currentSong = getCurrentSong();
    currentArt = currentSong.getAlbum().getArt();
    builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, currentArt);
    builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, currentArt);
    builder.putString(MediaMetadataCompat.METADATA_KEY_ART_URI, currentSong.getAlbum().getArtUri() == null ? null : currentSong.getAlbum().getArtUri().toString());
    builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, currentSong.getAlbum().getArtUri() == null ? null : currentSong.getAlbum().getArtUri().toString());
    builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, currentSong.getArtist().getName());
    builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, currentSong.getAlbum().getName());
    builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, currentSong.getTitle());
    builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, currentSong.getTitle());
    builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, currentSong.getArtist().getName() + " - " + currentSong.getAlbum().getName());
    builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, mPlayer.getDuration());
    MediaMetadataCompat metadata = builder.build();
    mSession.setMetadata(metadata);

    //send shuffle/repeat infos
    mSession.setShuffleMode(shuffleMode ? PlaybackStateCompat.SHUFFLE_MODE_NONE : PlaybackStateCompat.SHUFFLE_MODE_ALL);
    mSession.setRepeatMode(repeatMode);

    //set mediasession active if it was not
    if(!mSession.isActive()) mSession.setActive(true);

    /* update notification */
    if(mNotification == null)
    {
        mNotification = mNotificationManager.getNotification(currentSong, mPlayer.getCurrentState(), mSession.getSessionToken());
        startForeground(PlayerNotification.NOTIFICATION_ID, mNotification);
    }
    else
    {
        stopForeground(false);
        mNotification = mNotificationManager.getNotification(currentSong, mPlayer.getCurrentState(), mSession.getSessionToken());
        mNotificationManager.getNotificationManager().notify(PlayerNotification.NOTIFICATION_ID, mNotification);
    }
}