Example usage for android.media RemoteControlClient PLAYSTATE_PAUSED

List of usage examples for android.media RemoteControlClient PLAYSTATE_PAUSED

Introduction

In this page you can find the example usage for android.media RemoteControlClient PLAYSTATE_PAUSED.

Prototype

int PLAYSTATE_PAUSED

To view the source code for android.media RemoteControlClient PLAYSTATE_PAUSED.

Click Source Link

Document

Playback state of a RemoteControlClient which is paused.

Usage

From source file:com.iamplus.musicplayer.MusicService.java

void processPauseRequest() {
    if (mState == State.Playing) {
        // Pause media player and cancel the 'foreground service' state.
        mState = State.Paused;//from   w w  w.j  ava 2 s  .c o  m
        mPlayer.pause();
        relaxResources(false); // while paused, we always retain the MediaPlayer
        // do not give up audio focus
        if (mWakeLock.isHeld())
            mWakeLock.release();
    }

    // Tell any remote controls that our playback state is 'paused'.
    if (mRemoteControlClientCompat != null) {
        mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
    }
}

From source file:com.geryon.ocraa.MusicService.java

void processPauseRequest() {
    if (mState == State.Retrieving) {
        // If we are still retrieving media, clear the flag that indicates we should start
        // playing when we're ready
        progressBarHandler.removeCallbacks(mUpdateTimeTask);

        mStartPlayingAfterRetrieve = false;
        return;/*from   ww w  .  ja va 2 s. c o m*/
    }

    if (mState == State.Playing) {
        // Pause media player and cancel the 'foreground service' state.
        mState = State.Paused;
        mPlayer.pause();
        relaxResources(false); // while paused, we always retain the MediaPlayer
        // do not give up audio focus
    }

    // Tell any remote controls that our playback state is 'paused'.
    if (mRemoteControlClientCompat != null) {
        mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
    }
}

From source file:de.qspool.clementineremote.backend.ClementinePlayerConnection.java

/**
 * Register the RemoteControlClient//from w w  w.  j  a  va 2 s  . c o  m
 */
private void registerRemoteControlClient() {
    // Request AudioFocus, so the widget is shown on the lock-screen
    mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);

    mAudioManager.registerMediaButtonEventReceiver(mClementineMediaButtonEventReceiver);

    // Create the intent
    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setComponent(mClementineMediaButtonEventReceiver);
    PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(App.mApp.getApplicationContext(), 0,
            mediaButtonIntent, 0);
    // Create the client
    mRcClient = new RemoteControlClient(mediaPendingIntent);
    if (App.mClementine.getState() == Clementine.State.PLAY) {
        mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    } else {
        mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
    }
    mRcClient.setTransportControlFlags(
            RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
                    | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE);
    mAudioManager.registerRemoteControlClient(mRcClient);
}

From source file:com.namelessdev.mpdroid.NotificationService.java

/**
 * Get the RemoteControlClient status for the corresponding MPDStatus
 *
 * @param mpdStatus MPDStatus to parse/*  w  w w.j  a va 2 s.  co m*/
 * @return state to give to RemoteControlClient
 */
private int getRemoteState(final MPDStatus mpdStatus) {
    final int state;

    if (mpdStatus == null) {
        state = RemoteControlClient.PLAYSTATE_ERROR;
    } else if (mediaPlayerServiceIsBuffering) {
        state = RemoteControlClient.PLAYSTATE_BUFFERING;
    } else {
        switch (mpdStatus.getState()) {
        case MPDStatus.MPD_STATE_PLAYING:
            state = RemoteControlClient.PLAYSTATE_PLAYING;
            break;
        case MPDStatus.MPD_STATE_STOPPED:
            state = RemoteControlClient.PLAYSTATE_STOPPED;
            break;
        default:
            state = RemoteControlClient.PLAYSTATE_PAUSED;
            break;
        }
    }
    return state;
}

From source file:de.qspool.clementineremote.backend.ClementinePlayerConnection.java

/**
 * Update the RemoteControlClient/*ww  w  . j  a v a 2s .  c om*/
 */
private void updateRemoteControlClient() {
    // Update playstate
    if (App.mClementine.getState() == Clementine.State.PLAY) {
        mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    } else {
        mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
    }

    // Get the metadata editor
    if (mLastSong != null && mLastSong.getArt() != null) {
        RemoteControlClient.MetadataEditor editor = mRcClient.editMetadata(false);
        editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, mLastSong.getArt());

        // The RemoteControlClients displays the following info:
        // METADATA_KEY_TITLE (white) - METADATA_KEY_ALBUMARTIST (grey) - METADATA_KEY_ALBUM (grey)
        //
        // So i put the metadata not in the "correct" fields to display artist, track and album
        // TODO: Fix it when changed in newer android versions
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, mLastSong.getAlbum());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, mLastSong.getArtist());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, mLastSong.getTitle());
        editor.apply();
    }
}

From source file:com.andreadec.musicplayer.MusicService.java

private void updateNotificationMessage() {
    /* Update remote control client */
    if (Build.VERSION.SDK_INT >= 14) {
        if (currentPlayingItem == null) {
            remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        } else {/*from   ww  w  .java2 s  . co m*/
            if (isPlaying()) {
                remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
            } else {
                remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
            }
            RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, currentPlayingItem.getTitle());
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, currentPlayingItem.getArtist());
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST,
                    currentPlayingItem.getArtist());
            metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, getDuration());
            if (currentPlayingItem.hasImage()) {
                metadataEditor.putBitmap(METADATA_KEY_ARTWORK, currentPlayingItem.getImage());
            } else {
                metadataEditor.putBitmap(METADATA_KEY_ARTWORK, icon.copy(icon.getConfig(), false));
            }
            metadataEditor.apply();
        }
    }

    /* Update notification */
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setSmallIcon(R.drawable.audio_white);
    //notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
    notificationBuilder.setOngoing(true);

    int playPauseIcon = isPlaying() ? R.drawable.pause : R.drawable.play;
    //int playPauseString = isPlaying() ? R.string.pause : R.string.play;
    notificationBuilder.setContentIntent(pendingIntent);

    String notificationMessage = "";
    if (currentPlayingItem == null) {
        notificationMessage = getResources().getString(R.string.noSong);
    } else {
        if (currentPlayingItem.getArtist() != null && !currentPlayingItem.getArtist().equals(""))
            notificationMessage = currentPlayingItem.getArtist() + " - ";
        notificationMessage += currentPlayingItem.getTitle();
    }

    /*notificationBuilder.addAction(R.drawable.previous, getResources().getString(R.string.previous), previousPendingIntent);
    notificationBuilder.addAction(playPauseIcon, getResources().getString(playPauseString), playpausePendingIntent);
    notificationBuilder.addAction(R.drawable.next, getResources().getString(R.string.next), nextPendingIntent);*/
    notificationBuilder.setContentTitle(getResources().getString(R.string.app_name));
    notificationBuilder.setContentText(notificationMessage);

    notification = notificationBuilder.build();

    RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.layout_notification);

    if (currentPlayingItem == null) {
        notificationLayout.setTextViewText(R.id.textViewArtist, getString(R.string.app_name));
        notificationLayout.setTextViewText(R.id.textViewTitle, getString(R.string.noSong));
        notificationLayout.setImageViewBitmap(R.id.imageViewNotification,
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
    } else {
        notificationLayout.setTextViewText(R.id.textViewArtist, currentPlayingItem.getArtist());
        notificationLayout.setTextViewText(R.id.textViewTitle, currentPlayingItem.getTitle());
        Bitmap image = currentPlayingItem.getImage();
        if (image != null) {
            notificationLayout.setImageViewBitmap(R.id.imageViewNotification, image);
        } else {
            notificationLayout.setImageViewBitmap(R.id.imageViewNotification,
                    BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
        }
    }
    notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationQuit, quitPendingIntent);
    notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationPrevious, previousPendingIntent);
    notificationLayout.setImageViewResource(R.id.buttonNotificationPlayPause, playPauseIcon);
    notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationPlayPause, playpausePendingIntent);
    notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationNext, nextPendingIntent);
    notification.bigContentView = notificationLayout;

    notificationManager.notify(Constants.NOTIFICATION_MAIN, notification);
}

From source file:com.example.android.mediarouter.player.MainActivity.java

private void updateButtons() {
    MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute();
    // show pause or resume icon depending on current state
    mPauseResumeButton.setImageResource(mPaused ? R.drawable.ic_action_play : R.drawable.ic_action_pause);
    // disable pause/resume/stop if no session
    mPauseResumeButton.setEnabled(mSessionManager.hasSession());
    mStopButton.setEnabled(mSessionManager.hasSession());
    // only enable seek bar when duration is known
    PlaylistItem item = getCheckedPlaylistItem();
    mSeekBar.setEnabled(item != null && item.getDuration() > 0);
    if (mRemoteControlClient != null) {
        mRemoteControlClient.setPlaybackState(
                mPaused ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING);
    }/*ww  w  .  j  av  a 2s  .com*/
}

From source file:com.example.android.mediarouter.player.RadioActivity.java

private void updateButtons() {
    RouteInfo route = mMediaRouter.getSelectedRoute();
    // show pause or resume icon depending on current state
    mPauseResumeButton.setImageResource(mPaused ? R.drawable.ic_action_play : R.drawable.ic_action_pause);
    // disable pause/resume/stop if no session
    mPauseResumeButton.setEnabled(mSessionManager.hasSession());
    mStopButton.setEnabled(mSessionManager.hasSession());
    // only enable seek bar when duration is known
    PlaylistItem item = getCheckedPlaylistItem();
    mSeekBar.setEnabled(item != null && item.getDuration() > 0);
    if (mRemoteControlClient != null) {
        mRemoteControlClient.setPlaybackState(
                mPaused ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING);
    }//from   w w w .  j av a  2  s  .  c o  m
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.java

/**
 * Notify the change-receivers that something has changed.
 * The intent that is sent contains the following data
 * for the currently playing track:/*w  w  w .  j  a  v a 2 s. c  o  m*/
 * "id" - Integer: the database row ID
 * "artist" - String: the name of the artist
 * "album" - String: the name of the album
 * "track" - String: the name of the track
 * The intent has an action that is one of
 * "com.android.music.metachanged"
 * "com.android.music.queuechanged",
 * "com.android.music.playbackcomplete"
 * "com.android.music.playstatechanged"
 * respectively indicating that a new track has
 * started playing, that the playback queue has
 * changed, that playback has stopped because
 * the last file in the list has been played,
 * or that the play-state changed (paused/resumed).
 */
private void notifyChange(String what) {

    Intent i = new Intent(what);
    i.putExtra("id", Long.valueOf(getAudioId()));
    i.putExtra("artist", getArtistName());
    i.putExtra("album", getAlbumName());
    i.putExtra("track", getTrackName());
    i.putExtra("playing", isPlaying());
    sendStickyBroadcast(i);

    if (what.equals(PLAYSTATE_CHANGED)) {
        mRemoteControlClient.setPlaybackState(
                isPlaying() ? RemoteControlClient.PLAYSTATE_PLAYING : RemoteControlClient.PLAYSTATE_PAUSED);
    } else if (what.equals(META_CHANGED)) {
        RemoteControlClient.MetadataEditor ed = mRemoteControlClient.editMetadata(true);
        ed.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getTrackName());
        ed.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getAlbumName());
        ed.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getArtistName());
        ed.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration());
        Bitmap b = MusicUtils.getArtwork(this, getAudioId(), getAlbumId(), false);
        if (b != null) {
            ed.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, b);
        }
        ed.apply();
    }

    if (what.equals(QUEUE_CHANGED)) {
        saveQueue(true);
    } else {
        saveQueue(false);
    }

    // Share this notification directly with our widgets
    mAppWidgetProvider.notifyChange(this, what);
}

From source file:com.andrew.apolloMod.service.ApolloService.java

/**
 * Notify the change-receivers that something has changed. The intent that
 * is sent contains the following data for the currently playing track: "id"
 * - Integer: the database row ID "artist" - String: the name of the artist
 * "album" - String: the name of the album "track" - String: the name of the
 * track The intent has an action that is one of
 * "com.andrew.apolloMod.metachanged" "com.andrew.apolloMod.queuechanged",
 * "com.andrew.apolloMod.playbackcomplete" "com.andrew.apolloMod.playstatechanged"
 * respectively indicating that a new track has started playing, that the
 * playback queue has changed, that playback has stopped because the last
 * file in the list has been played, or that the play-state changed
 * (paused/resumed).//from  www. j a v  a 2s  . c o  m
 */
public void notifyChange(String what) {

    Intent i = new Intent(what);
    i.putExtra("id", Long.valueOf(getAudioId()));
    i.putExtra("artist", getArtistName());
    i.putExtra("album", getAlbumName());
    i.putExtra("track", getTrackName());
    i.putExtra("playing", mIsSupposedToBePlaying);
    i.putExtra("isfavorite", isFavorite());
    sendStickyBroadcast(i);

    i = new Intent(i);
    i.setAction(what.replace(APOLLO_PACKAGE_NAME, MUSIC_PACKAGE_NAME));
    sendStickyBroadcast(i);

    if (Constants.isApi14Supported()) {
        if (what.equals(PLAYSTATE_CHANGED)) {
            mRemoteControlClient.setPlaybackState(mIsSupposedToBePlaying ? RemoteControlClient.PLAYSTATE_PLAYING
                    : RemoteControlClient.PLAYSTATE_PAUSED);
        } else if (what.equals(META_CHANGED)) {
            RemoteControlClient.MetadataEditor ed = mRemoteControlClient.editMetadata(true);
            ed.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getTrackName());
            ed.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getAlbumName());
            ed.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getArtistName());
            ed.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration());
            Bitmap b = getAlbumBitmap();
            if (b != null) {
                ed.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, b);
            }
            ed.apply();
        }
    }
    if (what.equals(QUEUE_CHANGED)) {
        saveQueue(true);
    } else {
        saveQueue(false);
    }
    mAppWidgetProvider1x1.notifyChange(this, what);
    mAppWidgetProvider4x1.notifyChange(this, what);
    mAppWidgetProvider4x2.notifyChange(this, what);

}