List of usage examples for android.media RemoteControlClient PLAYSTATE_PLAYING
int PLAYSTATE_PLAYING
To view the source code for android.media RemoteControlClient PLAYSTATE_PLAYING.
Click Source Link
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 w w w . ja va2 s .co 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); }
From source file:org.moire.ultrasonic.service.DownloadServiceImpl.java
private void updateRemoteControl() { if (!Util.isLockScreenEnabled(this)) { clearRemoteControl();/*from w w w. j a va2 s . c om*/ return; } if (remoteControlClient != null) { audioManager.unregisterRemoteControlClient(remoteControlClient); audioManager.registerRemoteControlClient(remoteControlClient); } else { setUpRemoteControlClient(); } Log.i(TAG, String.format("In updateRemoteControl, playerState: %s [%d]", playerState, getPlayerPosition())); switch (playerState) { case STARTED: if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } else { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING, getPlayerPosition(), 1.0f); } break; default: if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); } else { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED, getPlayerPosition(), 1.0f); } break; } if (currentPlaying != null) { MusicDirectory.Entry currentSong = currentPlaying.getSong(); Bitmap lockScreenBitmap = FileUtil.getAlbumArtBitmap(this, currentSong, Util.getMinDisplayMetric(this), true); String artist = currentSong.getArtist(); String album = currentSong.getAlbum(); String title = currentSong.getTitle(); Integer currentSongDuration = currentSong.getDuration(); Long duration = 0L; if (currentSongDuration != null) duration = (long) currentSongDuration * 1000; remoteControlClient.editMetadata(true).putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, artist) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, artist) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, album) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, title) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration) .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, lockScreenBitmap).apply(); } }
From source file:com.adityarathi.muo.services.AudioPlaybackService.java
/** * Updates all remote control clients (including the lockscreen controls). *//*from w w w. j a v a 2 s.c om*/ public void updateRemoteControlClients(SongHelper songHelper) { try { //Update the remote controls mRemoteControlClientCompat.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getCurrentSong().getArtist()) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getCurrentSong().getTitle()) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getCurrentSong().getAlbum()) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, getCurrentMediaPlayer().getDuration()) .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, getCurrentSong().getAlbumArt()) .apply(); if (mRemoteControlClientCompat != null) { if (getCurrentMediaPlayer().isPlaying()) mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); else mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.Duo.music.player.Services.AudioPlaybackService.java
/** * Updates all remote control clients (including the lockscreen controls). *//*www . j ava 2 s .com*/ public void updateRemoteControlClients(SongHelper songHelper) { try { //Update the remote controls mRemoteControlClientCompat.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getCurrentSong().getArtist()) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getCurrentSong().getTitle()) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getCurrentSong().getAlbum()) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, getCurrentMediaPlayer().getDuration()) .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, getCurrentSong().getAlbumArt()) .apply(); if (mRemoteControlClientCompat != null) { if (getCurrentMediaPlayer().isPlaying()) mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); else mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.tomahawk.tomahawk_android.services.PlaybackService.java
/** * Update the playback controls/views which are being shown on the lockscreen *//* w w w . j av a 2 s . com*/ @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 w ww.ja va 2 s.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 *//* www. j ava 2s .c om*/ @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); } } }
From source file:com.firefly.sample.castcompanionlibrary.cast.VideoCastManager.java
@SuppressLint("InlinedApi") private void setUpRemoteControl(final MediaInfo info) { if (!isFeatureEnabled(BaseCastManager.FEATURE_LOCKSCREEN)) { return;/*from w ww.jav a 2s . c o m*/ } LOGD(TAG, "setupRemoteControl() was called"); mAudioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); ComponentName eventReceiver = new ComponentName(mContext, VideoIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(eventReceiver); if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat( PendingIntent.getBroadcast(mContext, 0, intent, 0)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.addToMediaRouter(mMediaRouter); mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE); if (null == info) { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); return; } else { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } // Update the remote control's image updateLockScreenImage(info); // update the remote control's metadata updateLockScreenMetadata(); }
From source file:air.com.snagfilms.cast.chromecast.VideoChromeCastManager.java
@SuppressLint("InlinedApi") private void setUpRemoteControl(final MediaInfo info) { if (!isFeatureEnabled(BaseChromeCastManager.FEATURE_LOCKSCREEN)) { return;// www. j a v a 2 s . co m } Log.d(TAG, "setupRemoteControl() was called"); mAudioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); ComponentName eventReceiver = new ComponentName(mContext, VideoIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(eventReceiver); if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat( PendingIntent.getBroadcast(mContext, 0, intent, 0)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.addToMediaRouter(mMediaRouter); mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE); if (null == info) { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); return; } else { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } // Update the remote control's image updateLockScreenImage(info); // update the remote control's metadata updateLockScreenMetadata(); }
From source file:com.firefly.sample.castcompanionlibrary.cast.VideoCastManager.java
@SuppressLint("InlinedApi") private void updateRemoteControl(boolean playing) { if (!isFeatureEnabled(FEATURE_LOCKSCREEN)) { return;/* w w w.j av a 2s . com*/ } if (!isConnected()) { removeRemoteControlClient(); return; } try { if (null == mRemoteControlClientCompat && playing) { setUpRemoteControl(getRemoteMediaInformation()); } if (mRemoteControlClientCompat != null) { int playState = isRemoteStreamLive() ? RemoteControlClient.PLAYSTATE_BUFFERING : RemoteControlClient.PLAYSTATE_PLAYING; mRemoteControlClientCompat .setPlaybackState(playing ? playState : RemoteControlClient.PLAYSTATE_PAUSED); } } catch (TransientNetworkDisconnectionException e) { LOGE(TAG, "Failed to setup RCC due to network issues", e); } catch (NoConnectionException e) { LOGE(TAG, "Failed to setup RCC due to network issues", e); } }