List of usage examples for android.support.v4.media.session PlaybackStateCompat PLAYBACK_POSITION_UNKNOWN
long PLAYBACK_POSITION_UNKNOWN
To view the source code for android.support.v4.media.session PlaybackStateCompat PLAYBACK_POSITION_UNKNOWN.
Click Source Link
From source file:net.simno.klingar.playback.PlaybackManager.java
void updatePlaybackState() { long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN; if (playback != null && playback.isConnected()) { position = playback.getCurrentStreamPosition(); }//w w w . j ava 2 s.c o m PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder() .setActions(getAvailableActions()); addCustomActions(stateBuilder); @State int state = playback.getState(); stateBuilder.setState(state, position, 1.0f, androidClock.elapsedRealTime()); serviceCallback.onPlaybackStateUpdated(stateBuilder.build()); if (state == PlaybackStateCompat.STATE_PLAYING || state == PlaybackStateCompat.STATE_PAUSED) { serviceCallback.onNotificationRequired(); } }
From source file:com.classiqo.nativeandroid_32bitz.playback.PlaybackManager.java
public void updatePlaybackState(String error) { LogHelper.d(TAG, "updatePlaybackState, playback state = " + mPlayback.getState()); long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN; if (mPlayback != null && mPlayback.isConnected()) { position = mPlayback.getCurrentStreamPosition(); }/*from w ww. ja v a 2 s . c om*/ //noinspection ResourceType PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder() .setActions(getAvailableActions()); setCustomAction(stateBuilder); int state = mPlayback.getState(); if (error != null) { stateBuilder.setErrorMessage(error); state = PlaybackStateCompat.STATE_ERROR; } //noinspection ResourceType stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime()); MediaSessionCompat.QueueItem currentMusic = mQueueManager.getCurrentMusic(); if (currentMusic != null) { stateBuilder.setActiveQueueItemId(currentMusic.getQueueId()); } mServiceCallback.onPlaybackStateUpdated(stateBuilder.build()); if (state == PlaybackStateCompat.STATE_PLAYING || state == PlaybackStateCompat.STATE_PAUSED) { mServiceCallback.onNotificationRequired(); } }
From source file:rocks.stalin.android.app.playback.PlaybackManager.java
/** * Update the current media player state, optionally showing an error message. * * @param error if not null, error message to present to the user. *///from w w w. j a v a 2 s . co m public void updatePlaybackState(String error) { LogHelper.d(TAG, "updatePlaybackState, playback state=" + mPlayback.getState()); long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN; if (mPlayback != null && mPlayback.isConnected()) { position = mPlayback.getCurrentStreamPosition(); } //noinspection ResourceType PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder() .setActions(getAvailableActions()); setCustomAction(stateBuilder); int state = mPlayback.getState(); // If there is an error message, send it to the playback state: if (error != null) { // Error states are really only supposed to be used for errors that cause playback to // stop unexpectedly and persist until the user takes action to fix it. stateBuilder.setErrorMessage(PlaybackStateCompat.ERROR_CODE_UNKNOWN_ERROR, error); state = PlaybackStateCompat.STATE_ERROR; } //noinspection ResourceType stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime()); // Set the activeQueueItemId if the current index is valid. MediaSessionCompat.QueueItem currentMusic = mQueueManager.getCurrentMusic(); if (currentMusic != null) { stateBuilder.setActiveQueueItemId(currentMusic.getQueueId()); } mServiceCallback.onPlaybackStateUpdated(stateBuilder.build()); if (state == PlaybackStateCompat.STATE_PLAYING || state == PlaybackStateCompat.STATE_PAUSED) { mServiceCallback.onNotificationRequired(); } }
From source file:com.appdevper.mediaplayer.app.PlaybackManager.java
/** * Update the current media player state, optionally showing an error message. * * @param error if not null, error message to present to the user. *//*from ww w . ja v a 2 s . c om*/ public void updatePlaybackState(String error) { LogHelper.d(TAG, "updatePlaybackState, playback state=" + mPlayback.getState()); long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN; if (mPlayback != null && mPlayback.isConnected()) { position = mPlayback.getCurrentStreamPosition(); } //noinspection ResourceType PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder() .setActions(getAvailableActions()); setCustomAction(stateBuilder); int state = mPlayback.getState(); // If there is an error message, send it to the playback state: if (error != null) { // Error states are really only supposed to be used for errors that cause playback to // stop unexpectedly and persist until the user takes action to fix it. stateBuilder.setErrorMessage(error); state = PlaybackStateCompat.STATE_ERROR; } //noinspection ResourceType stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime()); // Set the activeQueueItemId if the current index is valid. MediaSessionCompat.QueueItem currentMusic = mQueueManager.getCurrentMusic(); if (currentMusic != null) { stateBuilder.setActiveQueueItemId(currentMusic.getQueueId()); } mServiceCallback.onPlaybackStateUpdated(stateBuilder.build()); if (state == PlaybackStateCompat.STATE_PLAYING || state == PlaybackStateCompat.STATE_PAUSED) { mServiceCallback.onNotificationRequired(); } }
From source file:com.murati.oszk.audiobook.playback.PlaybackManager.java
/** * Update the current media player state, optionally showing an error message. * * @param error if not null, error message to present to the user. *///from w w w . j a va 2 s .c o m public void updatePlaybackState(String error) { LogHelper.d(TAG, "updatePlaybackState, playback state=" + mPlayback.getState()); long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN; if (mPlayback != null && mPlayback.isConnected()) { position = mPlayback.getCurrentStreamPosition(); } //noinspection ResourceType PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder() .setActions(getAvailableActions()); setCustomAction(stateBuilder); int state = mPlayback.getState(); // If there is an error message, send it to the playback state: if (error != null) { // Error states are really only supposed to be used for errors that cause playback to // stop unexpectedly and persist until the user takes action to fix it. stateBuilder.setErrorMessage(error); state = PlaybackStateCompat.STATE_ERROR; } //noinspection ResourceType stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime()); // Set the activeQueueItemId if the current index is valid. MediaSessionCompat.QueueItem currentMusic = mQueueManager.getCurrentTrack(); if (currentMusic != null) { stateBuilder.setActiveQueueItemId(currentMusic.getQueueId()); } mServiceCallback.onPlaybackStateUpdated(stateBuilder.build()); if (state == PlaybackStateCompat.STATE_PLAYING || state == PlaybackStateCompat.STATE_PAUSED) { mServiceCallback.onNotificationRequired(); } }
From source file:com.devbrackets.android.exomedia.EMLockScreen.java
/** * Sets the volatile information for the lock screen controls. This information is expected to * change frequently./*from ww w.j ava 2 s . c o m*/ * * @param title The title to display for the notification (e.g. A song name) * @param album The name of the album the media is found in * @param artist The name of the artist for the media item * @param notificationMediaState The current media state for the expanded (big) notification */ @SuppressWarnings("ResourceType") //getPlaybackOptions() and getPlaybackState() return the correctly annotated items public void updateLockScreenInformation(String title, String album, String artist, Bitmap mediaArtwork, EMNotification.NotificationMediaState notificationMediaState) { //Updates the current media MetaData MediaMetadataCompat.Builder metaDataBuilder = new MediaMetadataCompat.Builder(); metaDataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, appIconBitmap); metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, title); metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album); metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist); if (mediaArtwork != null) { metaDataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, mediaArtwork); } mediaSession.setMetadata(metaDataBuilder.build()); //Updates the available playback controls PlaybackStateCompat.Builder playbackStateBuilder = new PlaybackStateCompat.Builder(); playbackStateBuilder.setActions(getPlaybackOptions(notificationMediaState)); playbackStateBuilder.setState(getPlaybackState(notificationMediaState.isPlaying()), PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); mediaSession.setPlaybackState(playbackStateBuilder.build()); Log.d(TAG, "update, controller is null ? " + (mediaSession.getController() == null ? "true" : "false")); if (showLockScreen && !mediaSession.isActive()) { mediaSession.setActive(true); } }
From source file:com.devbrackets.android.playlistcore.helper.MediaControlsHelper.java
/** * Sets the volatile information for the remote views and controls. This information is expected to * change frequently./* w w w. j ava 2 s . co m*/ * * @param title The title to display for the notification (e.g. A song name) * @param album The name of the album the media is found in * @param artist The name of the artist for the media item * @param notificationMediaState The current media state for the expanded (big) notification */ @SuppressWarnings("ResourceType") //getPlaybackOptions() and getPlaybackState() return the correctly annotated items public void update(@Nullable String title, @Nullable String album, @Nullable String artist, @Nullable Bitmap mediaArtwork, @NonNull NotificationHelper.NotificationMediaState notificationMediaState) { //Updates the current media MetaData MediaMetadataCompat.Builder metaDataBuilder = new MediaMetadataCompat.Builder(); metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, title); metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album); metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist); if (appIconBitmap != null) { metaDataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, appIconBitmap); } if (mediaArtwork != null) { metaDataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, mediaArtwork); } if (mediaSession != null) { mediaSession.setMetadata(metaDataBuilder.build()); } //Updates the available playback controls PlaybackStateCompat.Builder playbackStateBuilder = new PlaybackStateCompat.Builder(); playbackStateBuilder.setActions(getPlaybackOptions(notificationMediaState)); playbackStateBuilder.setState(getPlaybackState(notificationMediaState.isPlaying()), PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); mediaSession.setPlaybackState(playbackStateBuilder.build()); Log.d(TAG, "update, controller is null ? " + (mediaSession.getController() == null ? "true" : "false")); if (enabled && !mediaSession.isActive()) { mediaSession.setActive(true); } }
From source file:nuclei.media.playback.PlaybackManager.java
/** * Update the current media player state, optionally showing an error message. * * @param error if not null, error message to present to the user. *///from ww w . jav a 2 s . co m public void updatePlaybackState(Exception error, boolean canPause) { long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN; if (mPlayback != null && mPlayback.isConnected()) { position = mPlayback.getCurrentStreamPosition(); } //noinspection ResourceType final PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder() .setActions(getAvailableActions()); int state = mPlayback == null ? PlaybackStateCompat.STATE_NONE : mPlayback.getState(); // If there is an error message, send it to the playback state: if (error != null) { mHandler.removeMessages(TIMER_COUNTDOWN); mHandler.removeMessages(TIMER_TIMING); int errorCode = ResourceProvider.getInstance().getExceptionCode(error); String message = ResourceProvider.getInstance().getExceptionMessage(error); if (message == null) message = error.getMessage(); // Error states are really only supposed to be used for errors that cause playback to // stop unexpectedly and persist until the user takes action to fix it. stateBuilder.setErrorMessage(errorCode, message); state = PlaybackStateCompat.STATE_ERROR; if (mPlayback != null) { int lastState = state; mPlayback.setState(state); if (mPlayback.isPlaying()) { mPlayback.setState(lastState); state = lastState; } else if (canPause) { mPlayback.pause(); } } MediaProvider.getInstance().onError(error); } float audioSpeed; if (mPlayback instanceof CastPlayback) audioSpeed = 1; else audioSpeed = mServiceCallback.getAudioSpeed(); //noinspection ResourceType stateBuilder.setState(state, position, audioSpeed, SystemClock.elapsedRealtime()); mServiceCallback.onPlaybackStateUpdated(stateBuilder.build()); if (state == PlaybackStateCompat.STATE_PLAYING) { if (mTimer > -1 && !mHandler.hasMessages(TIMER_COUNTDOWN)) mHandler.sendEmptyMessageDelayed(TIMER_COUNTDOWN, ONE_SECOND); if (mPlayback.getTiming() != null && !mHandler.hasMessages(TIMER_TIMING)) mHandler.sendEmptyMessageDelayed(TIMER_TIMING, ONE_SECOND); } if (state == PlaybackStateCompat.STATE_PLAYING) { mServiceCallback.onNotificationRequired(); } }
From source file:org.chromium.chrome.browser.media.ui.NotificationMediaPlaybackControls.java
private void updateNotification() { if (mService == null) return;//from ww w. ja va 2 s. c om if (mMediaNotificationInfo == null) { // Notification was hidden before we could update it. assert mNotificationBuilder == null; return; } // Android doesn't badge the icons for RemoteViews automatically when // running the app under the Work profile. if (mNotificationIcon == null) { Drawable notificationIconDrawable = ApiCompatibilityUtils.getUserBadgedIcon(mContext, R.drawable.audio_playing); mNotificationIcon = drawableToBitmap(notificationIconDrawable); } if (mNotificationBuilder == null) { mNotificationBuilder = new NotificationCompat.Builder(mContext).setSmallIcon(R.drawable.audio_playing) .setAutoCancel(false).setLocalOnly(true) .setDeleteIntent(mService.getPendingIntent(ListenerService.ACTION_STOP)); } mNotificationBuilder.setOngoing(!mMediaNotificationInfo.isPaused); mNotificationBuilder.setContentIntent(createContentIntent()); RemoteViews contentView = createContentView(); contentView.setTextViewText(R.id.title, mMediaNotificationInfo.title); contentView.setTextViewText(R.id.status, getStatus()); if (mNotificationIcon != null) { contentView.setImageViewBitmap(R.id.icon, mNotificationIcon); } else { contentView.setImageViewResource(R.id.icon, R.drawable.audio_playing); } if (mMediaNotificationInfo.isPaused) { contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidcontrol_play); contentView.setContentDescription(R.id.playpause, mPlayDescription); contentView.setOnClickPendingIntent(R.id.playpause, mService.getPendingIntent(ListenerService.ACTION_PLAY)); } else { contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidcontrol_pause); contentView.setContentDescription(R.id.playpause, mPauseDescription); contentView.setOnClickPendingIntent(R.id.playpause, mService.getPendingIntent(ListenerService.ACTION_PAUSE)); } mNotificationBuilder.setContent(contentView); mNotificationBuilder.setVisibility(mMediaNotificationInfo.isPrivate ? NotificationCompat.VISIBILITY_PRIVATE : NotificationCompat.VISIBILITY_PUBLIC); if (mMediaSession == null) { mMediaSession = new MediaSessionCompat(mContext, mContext.getString(R.string.app_name), new ComponentName(mContext.getPackageName(), MediaButtonReceiver.class.getName()), null); mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mMediaSession.setCallback(mMediaSessionCallback); mMediaSession.setActive(true); } mMediaSession.setMetadata(createMetadata()); PlaybackStateCompat.Builder playbackStateBuilder = new PlaybackStateCompat.Builder() .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE); if (mMediaNotificationInfo.isPaused) { playbackStateBuilder.setState(PlaybackStateCompat.STATE_PAUSED, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); } else { playbackStateBuilder.setState(PlaybackStateCompat.STATE_PLAYING, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); } mMediaSession.setPlaybackState(playbackStateBuilder.build()); Notification notification = mNotificationBuilder.build(); // We keep the service as a foreground service while the media is playing. When it is not, // the service isn't stopped but is no longer in foreground, thus at a lower priority. // While the service is in foreground, the associated notification can't be swipped away. // Moving it back to background allows the user to remove the notification. if (mMediaNotificationInfo.isPaused) { mService.stopForeground(false /* removeNotification */); NotificationManagerCompat manager = NotificationManagerCompat.from(mContext); manager.notify(R.id.media_playback_notification, notification); } else { mService.startForeground(R.id.media_playback_notification, notification); } }
From source file:org.chromium.chrome.browser.media.ui.MediaNotificationManager.java
private void updateMediaSession() { if (!mMediaNotificationInfo.supportsPlayPause()) return;/*ww w . ja va 2 s. co m*/ if (mMediaSession == null) mMediaSession = createMediaSession(); try { // Tell the MediaRouter about the session, so that Chrome can control the volume // on the remote cast device (if any). // Pre-MR1 versions of JB do not have the complete MediaRouter APIs, // so getting the MediaRouter instance will throw an exception. MediaRouter.getInstance(mContext).setMediaSessionCompat(mMediaSession); } catch (NoSuchMethodError e) { // Do nothing. Chrome can't be casting without a MediaRouter, so there is nothing // to do here. } mMediaSession.setMetadata(createMetadata()); PlaybackStateCompat.Builder playbackStateBuilder = new PlaybackStateCompat.Builder() .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE); if (mMediaNotificationInfo.isPaused) { playbackStateBuilder.setState(PlaybackStateCompat.STATE_PAUSED, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); } else { // If notification only supports stop, still pretend playbackStateBuilder.setState(PlaybackStateCompat.STATE_PLAYING, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); } mMediaSession.setPlaybackState(playbackStateBuilder.build()); }