Example usage for android.media RemoteControlClient PLAYSTATE_STOPPED

List of usage examples for android.media RemoteControlClient PLAYSTATE_STOPPED

Introduction

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

Prototype

int PLAYSTATE_STOPPED

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

Click Source Link

Document

Playback state of a RemoteControlClient which is stopped.

Usage

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

void processStopRequest(boolean force) {
    if (mState == State.Playing || mState == State.Paused || force) {
        mState = State.Stopped;/*  w  ww  .j a  va 2  s.c o  m*/
        progressBarHandler.removeCallbacks(mUpdateTimeTask);

        // let go of all resources...
        relaxResources(true);
        giveUpAudioFocus();

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

        // service is no longer necessary. Will be started again if needed.
        stopSelf();
    }
}

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  w w  w  .  j a  v a  2s. c  o  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:the.joevlc.AudioService.java

private void stop() {
    mLibVLC.stop();//  www  .jav  a 2s. c  o  m
    mEventManager.removeHandler(mEventHandler);
    setRemoteControlClientPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
    mCurrentMedia = null;
    mMediaList.clear();
    mPrevious.clear();
    mHandler.removeMessages(SHOW_PROGRESS);
    hideNotification();
    executeUpdate();
    changeAudioFocus(false);
}

From source file:org.videolan.vlc.AudioService.java

private void stop() {
    mLibVLC.stop();//from ww  w  .j  ava 2  s  .  c om
    mEventHandler.removeHandler(mVlcEventHandler);
    setRemoteControlClientPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
    mCurrentMedia = null;
    mMediaList.clear();
    mPrevious.clear();
    mHandler.removeMessages(SHOW_PROGRESS);
    hideNotification();
    executeUpdate();
    changeAudioFocus(false);
}

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

@Override
public void onDestroy() {
    super.onDestroy();
    Log.d(TAG, "Removing connection lock");
    app.removeConnectionLock(this);
    app.oMPDAsyncHelper.removeStatusChangeListener(this);
    delayedPauseHandler.removeCallbacksAndMessages(null);

    app.getApplicationState().notificationMode = false;

    windDownResources();//  ww  w  .j  ava 2  s  .co  m

    if (mAlbumCover != null && !mAlbumCover.isRecycled()) {
        mAlbumCover.recycle();
    }

    if (mAudioManager != null) {
        if (mRemoteControlClient != null) {
            mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
            mAudioManager.unregisterRemoteControlClient(mRemoteControlClient);
        }

        if (mMediaButtonReceiverComponent != null) {
            mAudioManager.unregisterMediaButtonEventReceiver(mMediaButtonReceiverComponent);
        }

        mAudioManager.abandonAudioFocus(null);
    }
}

From source file:org.moire.ultrasonic.service.DownloadServiceImpl.java

private void clearRemoteControl() {
    if (remoteControlClient != null) {
        remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        audioManager.unregisterRemoteControlClient(remoteControlClient);
        remoteControlClient = null;//from w w  w .j  a v a2  s. c  o m
    }
}

From source file:org.tomahawk.tomahawk_android.services.PlaybackService.java

/**
 * Update the playback controls/views which are being shown on the lockscreen
 *//*from  w w w.  ja v a2s .  co m*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateLockscreenControls() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        Log.d(TAG, "updateLockscreenControls()");
        // Use the media button APIs (if available) to register ourselves for media button
        // events
        MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent);

        if (mRemoteControlClientCompat == null) {
            Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
            intent.setComponent(mMediaButtonReceiverComponent);
            mRemoteControlClientCompat = new RemoteControlClientCompat(
                    PendingIntent.getBroadcast(PlaybackService.this /*context*/, 0 /*requestCode, ignored*/,
                            intent /*intent*/, 0 /*flags*/));
            RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat);
        }

        // Use the remote control APIs (if available) to set the playback state
        if (isPlaying()) {
            mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
        } else {
            mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        }

        int flags = RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE;
        if (hasNextEntry()) {
            flags |= RemoteControlClient.FLAG_KEY_MEDIA_NEXT;
        }
        if (hasPreviousEntry()) {
            flags |= RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS;
        }
        mRemoteControlClientCompat.setTransportControlFlags(flags);

        // Update the remote controls
        synchronized (this) {
            RemoteControlClientCompat.MetadataEditorCompat editor = mRemoteControlClientCompat
                    .editMetadata(true);
            editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST,
                    getCurrentQuery().getArtist().getPrettyName())
                    .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST,
                            getCurrentQuery().getArtist().getPrettyName())
                    .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getCurrentQuery().getPrettyName())
                    .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION,
                            getCurrentQuery().getPreferredTrack().getDuration());
            if (!TextUtils.isEmpty(getCurrentQuery().getAlbum().getPrettyName())) {
                editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM,
                        getCurrentQuery().getAlbum().getPrettyName());
            }
            editor.apply();
            Log.d(TAG, "Setting lockscreen metadata to: " + getCurrentQuery().getArtist().getPrettyName() + ", "
                    + getCurrentQuery().getPrettyName());
        }

        Picasso.with(TomahawkApp.getContext()).cancelRequest(mLockscreenTarget);
        ImageUtils.loadImageIntoBitmap(TomahawkApp.getContext(), getCurrentQuery().getImage(),
                mLockscreenTarget, Image.getLargeImageSize(), getCurrentQuery().hasArtistImage());
    }
}

From source file:com.andrew.apollo.MusicPlaybackService.java

/**
 * Updates the lock screen controls./*from  ww w.  j a  v a2s  .c o  m*/
 *
 * @param what The broadcast
 */
private void updateRemoteControlClient(final String what) {
    if (mRemoteControlClient == null) {
        LOG.info("mRemoteControlClient is null, review your logic");
        return;
    }

    int playState;
    if (isPlaying()) {
        playState = RemoteControlClient.PLAYSTATE_PLAYING;
    } else {
        playState = RemoteControlClient.PLAYSTATE_PAUSED;
        if (what.equals(PLAYSTATE_STOPPED)) {
            playState = RemoteControlClient.PLAYSTATE_STOPPED;
        }
    }

    if (what == null) {
        return;
    }

    if (PLAYSTATE_STOPPED.equals(what) && mNotificationHelper != null) {
        mNotificationHelper.killNotification();
    }

    switch (what) {
    case PLAYSTATE_CHANGED:
    case POSITION_CHANGED:
    case PLAYSTATE_STOPPED:
        async(mRemoteControlClient, MusicPlaybackService::remoteControlClientSetPlaybackStateTask, playState);
        break;
    case META_CHANGED:
    case QUEUE_CHANGED:
        // Asynchronously gets bitmap and then updates the Remote Control Client with that bitmap
        async(this, MusicPlaybackService::changeRemoteControlClientTask, playState, position());
        break;
    }
}

From source file:org.tomahawk.tomahawk_android.services.PlaybackService.java

/**
 * Create or update an ongoing notification
 *///w ww.j  a  v  a2s .co  m
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void updateLockscreenPlayState() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && getCurrentQuery() != null) {
        Log.d(TAG, "updateLockscreenPlayState()");
        if (isPlaying()) {
            mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
        } else {
            mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        }
    }
}