@Override public View getView(int position, View convertView, ViewGroup parent) { MediaBrowserCompat.MediaItem item = getItem(position); int itemState = MediaItemViewHolder.STATE_NONE; if (item.isPlayable()) { String itemMediaId = item.getDescription().getMediaId(); int playbackState = PlaybackStateCompat.STATE_NONE; if (mCurrentState != null) { playbackState = mCurrentState.getState(); } if (mCurrentMetadata != null && itemMediaId.equals(mCurrentMetadata.getDescription().getMediaId())) { if (playbackState == PlaybackState.STATE_PLAYING || playbackState == PlaybackState.STATE_BUFFERING) { itemState = MediaItemViewHolder.STATE_PLAYING; } else if (playbackState != PlaybackState.STATE_ERROR) { itemState = MediaItemViewHolder.STATE_PAUSED; } } } return MediaItemViewHolder.setupView( (Activity) getContext(), convertView, parent, item.getDescription(), itemState); }
private long getAvailableActions(int nextState) { long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PLAY_FROM_SEARCH | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS | PlaybackState.ACTION_FAST_FORWARD | PlaybackState.ACTION_REWIND | PlaybackState.ACTION_PAUSE; if (nextState == PlaybackState.STATE_PLAYING) { actions |= PlaybackState.ACTION_PAUSE; } return actions; }
@Override public void onSkipToPrevious() { // Update the media to skip to the previous video. setPlaybackState(PlaybackState.STATE_SKIPPING_TO_PREVIOUS); Bundle bundle = new Bundle(); bundle.putBoolean(AUTO_PLAY, true); int prevIndex = --mQueueIndex; if (prevIndex >= 0) { MediaSessionCompat.QueueItem item = mQueue.get(prevIndex); String mediaId = item.getDescription().getMediaId(); getActivity().getMediaController() .getTransportControls() .playFromMediaId(mediaId, bundle); } else { getActivity().onBackPressed(); // Return to details presenter. } }
public void playPause(String streamUrl) { if (mediaPlayer.isPlaying()) { mediaPlayer.pause(); updateMediaSession(PlaybackState.STATE_PAUSED); } else { if (!initPlayer) { new Player().execute(streamUrl); } else { if (!mediaPlayer.isPlaying()) { mediaPlayer.start(); updateMediaSession(PlaybackState.STATE_PLAYING); } } } }
private void updateMediaSession(int state) { MediaMetadata.Builder mediaBuilder = null; Bitmap bitmap = null; try { URL url = new URL(mRadioIcon); bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream()); } catch (IOException e) { Log.e(TAG, "BitmapFactory.decodeStream", e); } mediaBuilder = new MediaMetadata.Builder(); mediaBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, mTitle); if (bitmap != null) { mediaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap); } mMediaSession.setMetadata(mediaBuilder.build()); PlaybackState.Builder stateBuilder = new PlaybackState.Builder(); stateBuilder.setState(state, 0, 1.0f); mMediaSession.setPlaybackState(stateBuilder.build()); }
/** * Resumes playback. */ public void play() throws IllegalStateException { if (DEBUG) Log.d(TAG, "play()"); if (!isPlaybackPrepared()) { throw new IllegalStateException("Recorded program not set or video not ready yet"); } switch (mPlaybackState) { case PlaybackState.STATE_FAST_FORWARDING: case PlaybackState.STATE_REWINDING: setPlaybackSpeed(1); break; default: mTvView.timeShiftResume(); } mPlaybackState = PlaybackState.STATE_PLAYING; mCallback.onPlaybackStateChanged(mPlaybackState, 1); }
/** * Pauses playback. */ public void pause() throws IllegalStateException { if (DEBUG) Log.d(TAG, "pause()"); if (!isPlaybackPrepared()) { throw new IllegalStateException("Recorded program not set or playback not started yet"); } switch (mPlaybackState) { case PlaybackState.STATE_FAST_FORWARDING: case PlaybackState.STATE_REWINDING: setPlaybackSpeed(1); // falls through case PlaybackState.STATE_PLAYING: mTvView.timeShiftPause(); mPlaybackState = PlaybackState.STATE_PAUSED; break; default: break; } mCallback.onPlaybackStateChanged(mPlaybackState, 1); }
/** * Rewinds playback with the given speed. If the given speed is larger than * {@value #MAX_REWIND_SPEED}, uses {@value #MAX_REWIND_SPEED}. */ public void rewind(int speed) throws IllegalStateException { if (DEBUG) Log.d(TAG, "rewind()"); if (!isPlaybackPrepared()) { throw new IllegalStateException("Recorded program not set or playback not started yet"); } if (speed <= 0) { throw new IllegalArgumentException("Speed cannot be negative or 0"); } if (mTimeShiftCurrentPositionMs <= REWIND_POSITION_MARGIN_MS) { return; } speed = Math.min(speed, MAX_REWIND_SPEED); if (DEBUG) Log.d(TAG, "Let's play with speed: " + speed); setPlaybackSpeed(-speed); mPlaybackState = PlaybackState.STATE_REWINDING; mCallback.onPlaybackStateChanged(mPlaybackState, speed); }
/** * Seeks playback to the specified position. */ public void seekTo(long positionMs) throws IllegalStateException { if (DEBUG) Log.d(TAG, "seekTo()"); if (!isPlaybackPrepared()) { throw new IllegalStateException("Recorded program not set or playback not started yet"); } if (mProgram == null || mPlaybackState == PlaybackState.STATE_NONE) { return; } positionMs = getRealSeekPosition(positionMs, SEEK_POSITION_MARGIN_MS); if (DEBUG) Log.d(TAG, "Now: " + getPlaybackPosition() + ", shift to: " + positionMs); mTvView.timeShiftSeekTo(positionMs + mStartPositionMs); if (mPlaybackState == PlaybackState.STATE_FAST_FORWARDING || mPlaybackState == PlaybackState.STATE_REWINDING) { mPlaybackState = PlaybackState.STATE_PLAYING; mTvView.timeShiftResume(); mCallback.onPlaybackStateChanged(mPlaybackState, 1); } }
private void resumeToWatchedPositionIfNeeded() { if (mInitialSeekPositionMs != TvInputManager.TIME_SHIFT_INVALID_TIME) { mTvView.timeShiftSeekTo(getRealSeekPosition(mInitialSeekPositionMs, SEEK_POSITION_MARGIN_MS) + mStartPositionMs); mInitialSeekPositionMs = TvInputManager.TIME_SHIFT_INVALID_TIME; } if (mPauseOnPrepared) { mTvView.timeShiftPause(); mPlaybackState = PlaybackState.STATE_PAUSED; mPauseOnPrepared = false; } else { mTvView.timeShiftResume(); mPlaybackState = PlaybackState.STATE_PLAYING; } mCallback.onPlaybackStateChanged(mPlaybackState, 1); }
@Override public void onFastForward() { if (!mDvrPlayer.isPlaybackPrepared()) { return; } if (mDvrPlayer.getPlaybackState() == PlaybackState.STATE_FAST_FORWARDING) { if (mSpeedLevel < TimeShiftUtils.MAX_SPEED_LEVEL) { mSpeedLevel++; } else { return; } } else { mSpeedLevel = 0; } mDvrPlayer.fastForward( TimeShiftUtils.getPlaybackSpeed(mSpeedLevel, mProgramDurationMs)); }
@Override public void onRewind() { if (!mDvrPlayer.isPlaybackPrepared()) { return; } if (mDvrPlayer.getPlaybackState() == PlaybackState.STATE_REWINDING) { if (mSpeedLevel < TimeShiftUtils.MAX_SPEED_LEVEL) { mSpeedLevel++; } else { return; } } else { mSpeedLevel = 0; } mDvrPlayer.rewind(TimeShiftUtils.getPlaybackSpeed(mSpeedLevel, mProgramDurationMs)); }
@Override protected void updatePlayPauseState() { EventBus.getDefault().post(new ToggleSubtitleEvent(mIsSubtitleEnabled)); EventBus.getDefault().post(new UpdatePlaybackStateEvent(isPlaying())); if (mMediaSession != null) { PlaybackState.Builder builder = new PlaybackState.Builder(); builder.setActions(isPlaying() ? PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PAUSE : PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PLAY); builder.setState( isPlaying() ? PlaybackState.STATE_PLAYING : PlaybackState.STATE_PAUSED, getCurrentTime(), 1.0f); mMediaSession.setPlaybackState(builder.build()); } }
@Override protected void onProgressChanged(long currentTime, long duration) { EventBus.getDefault().post(new PlaybackProgressChangedEvent(currentTime, duration)); if (mMediaSession != null && duration > 0) { PlaybackState.Builder builder = new PlaybackState.Builder(); builder.setActions(isPlaying() ? PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PAUSE : PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PLAY); builder.setState( isPlaying() ? PlaybackState.STATE_PLAYING : PlaybackState.STATE_PAUSED, getCurrentTime(), 1.0f); mMediaSession.setPlaybackState(builder.build()); if (!mMediaSessionMetadataApplied) { setupMediaMetadata(); } } }
public void setPlaybackState(PlaybackState playbackState) { if (playbackItem == null) { return; } playbackItem.updateAmountPlayed(); int state = playbackState.getState(); boolean isPlaying = state == PlaybackState.STATE_PLAYING; if (isPlaying) { Log.d(TAG, "Track playing"); postEvent(playbackItem.getTrack()); playbackItem.startPlaying(); notificationManager.updateNowPlaying(playbackItem.getTrack()); scheduleSubmission(); } else { Log.d(TAG, String.format("Track paused (state %d)", state)); postEvent(Track.empty()); playbackItem.stopPlaying(); notificationManager.removeNowPlaying(); scrobbler.submit(playbackItem); } }
@Override public void onCreate() { Log.d (TAG, "onCreate() " + this) ; super.onCreate(); // Start a new MediaSession mediaSession = new MediaSession(this, "MuziKarMusicService"); mediaSession.setCallback(mediaSessionCallback); mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS); setSessionToken(mediaSession.getSessionToken()); playbackControlEventBroadcastReceiver = new PlaybackControlEventBroadcastReceiver(this); audioPlaybackHelper = new AudioPlaybackHelper(getApplicationContext(), new AudioPlaybackHelper.PlayStateChangeCallback() { @Override public void onPlaybackStatusChanged(PlaybackState state) { mediaSession.setPlaybackState(state); playbackControlEventBroadcastReceiver.update(audioPlaybackHelper.getCurrentMedia(), state, getSessionToken()); } }); carConnectStatusBroadcastReceiver = new CarConnectStatusBroadcastReceiver( this ) ; }
@Override public View getView(int position, View convertView, ViewGroup parent) { MediaBrowser.MediaItem item = getItem(position); int itemState = MediaItemViewHolder.STATE_NONE; if (item.isPlayable()) { String itemMediaId = item.getDescription().getMediaId(); int playbackState = PlaybackState.STATE_NONE; if (mCurrentState != null) { playbackState = mCurrentState.getState(); } if (mCurrentMetadata != null && itemMediaId.equals(mCurrentMetadata.getDescription().getMediaId())) { if (playbackState == PlaybackState.STATE_PLAYING || playbackState == PlaybackState.STATE_BUFFERING) { itemState = MediaItemViewHolder.STATE_PLAYING; } else if (playbackState != PlaybackState.STATE_ERROR) { itemState = MediaItemViewHolder.STATE_PAUSED; } } } return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent, item.getDescription(), itemState); }
private void setCustomAction(PlaybackState.Builder stateBuilder) { MediaMetadata currentMusic = getCurrentPlayingMusic(); if (currentMusic != null) { // Set appropriate "Favorite" icon on Custom action: String musicId = currentMusic.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); int favoriteIcon = R.drawable.ic_star_off; if (mMusicProvider.isFavorite(musicId)) { favoriteIcon = R.drawable.ic_star_on; } LogHelper.d(TAG, "updatePlaybackState, setting Favorite custom action of music ", musicId, " current favorite=", mMusicProvider.isFavorite(musicId)); Bundle customActionExtras = new Bundle(); WearHelper.setShowCustomActionOnWear(customActionExtras, true); stateBuilder.addCustomAction(new PlaybackState.CustomAction.Builder( CUSTOM_ACTION_THUMBS_UP, getString(R.string.favorite), favoriteIcon) .setExtras(customActionExtras) .build()); } }
@Override public void onCreate() { super.onCreate(); // Start a new MediaSession mSession = new MediaSession(this, "MusicService"); mSession.setCallback(mCallback); mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS); setSessionToken(mSession.getSessionToken()); final MediaNotificationManager mediaNotificationManager = new MediaNotificationManager(this); mPlayback = new PlaybackManager(this, new PlaybackManager.Callback() { @Override public void onPlaybackStatusChanged(PlaybackState state) { mSession.setPlaybackState(state); mediaNotificationManager.update(mPlayback.getCurrentMedia(), state, getSessionToken()); } }); }
@Override public void play(QueueItem item) { try { loadMedia(item.getDescription().getMediaId(), true); mState = PlaybackState.STATE_BUFFERING; if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } } catch (TransientNetworkDisconnectionException | NoConnectionException | JSONException | IllegalArgumentException e) { LogHelper.e(TAG, "Exception loading media ", e, null); if (mCallback != null) { mCallback.onError(e.getMessage()); } } }
@Override public void stop(boolean notifyListeners) { mState = PlaybackState.STATE_STOPPED; if (notifyListeners && mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } mCurrentPosition = getCurrentStreamPosition(); // Give up Audio focus giveUpAudioFocus(); unregisterAudioNoisyReceiver(); // Relax all resources relaxResources(true); if (mWifiLock.isHeld()) { mWifiLock.release(); } }
@Override public void pause() { if (mState == PlaybackState.STATE_PLAYING) { // Pause media player and cancel the 'foreground service' state. if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); mCurrentPosition = mMediaPlayer.getCurrentPosition(); } // while paused, retain the MediaPlayer but give up audio focus relaxResources(false); giveUpAudioFocus(); } mState = PlaybackState.STATE_PAUSED; if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } unregisterAudioNoisyReceiver(); }
@Override public void seekTo(int position) { LogHelper.d(TAG, "seekTo called with ", position); if (mMediaPlayer == null) { // If we do not have a current media player, simply update the current position mCurrentPosition = position; } else { if (mMediaPlayer.isPlaying()) { mState = PlaybackState.STATE_BUFFERING; } mMediaPlayer.seekTo(position); if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } } }
protected void updatePlaybackState(PlaybackState state) { if (mPlaybackControlsRow == null) { // We only update playback state after we get a valid metadata. return; } mLastPosition = state.getPosition(); mLastPositionUpdateTime = state.getLastPositionUpdateTime(); switch (state.getState()) { case PlaybackState.STATE_PLAYING: startProgressAutomation(); mPlayPauseAction.setIndex(PlayPauseAction.PAUSE); break; case PlaybackState.STATE_PAUSED: stopProgressAutomation(); mPlayPauseAction.setIndex(PlayPauseAction.PLAY); break; } updatePlayListRow(getActivity().getMediaController().getQueue()); mRowsAdapter.notifyArrayItemRangeChanged( mRowsAdapter.indexOf(mPlaybackControlsRow), 1); }
@Override public View getView(int position, View convertView, ViewGroup parent) { MediaBrowser.MediaItem item = getItem(position); int itemState = MediaItemViewHolder.STATE_NONE; if (item.isPlayable()) { itemState = MediaItemViewHolder.STATE_PLAYABLE; MediaController controller = ((Activity) getContext()).getMediaController(); if (controller != null && controller.getMetadata() != null) { String currentPlaying = controller.getMetadata().getDescription().getMediaId(); String musicId = MediaIDHelper.extractMusicIDFromMediaID( item.getDescription().getMediaId()); if (currentPlaying != null && currentPlaying.equals(musicId)) { PlaybackState pbState = controller.getPlaybackState(); if (pbState == null || pbState.getState() == PlaybackState.STATE_ERROR) { itemState = MediaItemViewHolder.STATE_NONE; } else if (pbState.getState() == PlaybackState.STATE_PLAYING) { itemState = MediaItemViewHolder.STATE_PLAYING; } else { itemState = MediaItemViewHolder.STATE_PAUSED; } } } } return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent, item.getDescription(), itemState); }
@Override public void onClick(View v) { PlaybackState stateObj = getActivity().getMediaController().getPlaybackState(); final int state = stateObj == null ? PlaybackState.STATE_NONE : stateObj.getState(); LogHelper.d(TAG, "Button pressed, in state " + state); switch (v.getId()) { case R.id.play_pause: LogHelper.d(TAG, "Play button pressed, in state " + state); if (state == PlaybackState.STATE_PAUSED || state == PlaybackState.STATE_STOPPED || state == PlaybackState.STATE_NONE) { playMedia(); } else if (state == PlaybackState.STATE_PLAYING || state == PlaybackState.STATE_BUFFERING || state == PlaybackState.STATE_CONNECTING) { pauseMedia(); } break; } }
/** * Check if the MediaSession is active and in a "playback-able" state * (not NONE and not STOPPED). * * @return true if the MediaSession's state requires playback controls to be visible. */ protected boolean shouldShowControls() { MediaController mediaController = getMediaController(); if (mediaController == null || mediaController.getMetadata() == null || mediaController.getPlaybackState() == null) { return false; } switch (mediaController.getPlaybackState().getState()) { case PlaybackState.STATE_ERROR: case PlaybackState.STATE_NONE: case PlaybackState.STATE_STOPPED: return false; default: return true; } }
private void connectToSession(MediaSession.Token token) { MediaController mediaController = new MediaController(FullScreenPlayerActivity.this, token); if (mediaController.getMetadata() == null) { finish(); return; } setMediaController(mediaController); mediaController.registerCallback(mCallback); PlaybackState state = mediaController.getPlaybackState(); updatePlaybackState(state); MediaMetadata metadata = mediaController.getMetadata(); if (metadata != null) { updateMediaDescription(metadata.getDescription()); updateDuration(metadata); } updateProgress(); if (state != null && (state.getState() == PlaybackState.STATE_PLAYING || state.getState() == PlaybackState.STATE_BUFFERING)) { scheduleSeekbarUpdate(); } }
private void updateProgress() { if (mLastPlaybackState == null) { return; } long currentPosition = mLastPlaybackState.getPosition(); if (mLastPlaybackState.getState() != PlaybackState.STATE_PAUSED) { // Calculate the elapsed time between the last position update and now and unless // paused, we can assume (delta * speed) + current position is approximately the // latest position. This ensure that we do not repeatedly call the getPlaybackState() // on MediaController. long timeDelta = SystemClock.elapsedRealtime() - mLastPlaybackState.getLastPositionUpdateTime(); currentPosition += (int) timeDelta * mLastPlaybackState.getPlaybackSpeed(); } mSeekbar.setProgress((int) currentPosition); }
private void addPlayPauseAction(Notification.Builder builder) { LogHelper.d(TAG, "updatePlayPauseAction"); String label; int icon; PendingIntent intent; if (mPlaybackState.getState() == PlaybackState.STATE_PLAYING) { label = mService.getString(R.string.label_pause); icon = R.drawable.uamp_ic_pause_white_24dp; intent = mPauseIntent; } else { label = mService.getString(R.string.label_play); icon = R.drawable.uamp_ic_play_arrow_white_24dp; intent = mPlayIntent; } builder.addAction(new Notification.Action(icon, label, intent)); }
private void setNotificationPlaybackState(Notification.Builder builder) { LogHelper.d(TAG, "updateNotificationPlaybackState. mPlaybackState=" + mPlaybackState); if (mPlaybackState == null || !mStarted) { LogHelper.d(TAG, "updateNotificationPlaybackState. cancelling notification!"); mService.stopForeground(true); return; } if (mPlaybackState.getState() == PlaybackState.STATE_PLAYING && mPlaybackState.getPosition() >= 0) { LogHelper.d(TAG, "updateNotificationPlaybackState. updating playback position to ", (System.currentTimeMillis() - mPlaybackState.getPosition()) / 1000, " seconds"); builder .setWhen(System.currentTimeMillis() - mPlaybackState.getPosition()) .setShowWhen(true) .setUsesChronometer(true); } else { LogHelper.d(TAG, "updateNotificationPlaybackState. hiding playback position"); builder .setWhen(0) .setShowWhen(false) .setUsesChronometer(false); } // Make sure that the notification can be dismissed by the user when we are not playing: builder.setOngoing(mPlaybackState.getState() == PlaybackState.STATE_PLAYING); }
public static void updateMediaSession(boolean updateMetadata, MediaMetadata.Builder mediaBuilder, final MediaSession mediaSession, final int playbackState, final long position, final float speed) { if (mediaSession.isActive()) { if (updateMetadata) { mediaSession.setMetadata(mediaBuilder.build()); } PlaybackState.Builder stateBuilder = new PlaybackState.Builder(); stateBuilder.setState(playbackState, position, speed); mediaSession.setPlaybackState(stateBuilder.build()); } }
private void updatePlaybackState(int playbackState) { PlaybackState.Builder state = new PlaybackState.Builder(); long position = player.getCurrentPosition(); if (ExoPlayer.STATE_PREPARING == playbackState) { state.setState(PlaybackState.STATE_CONNECTING, position, 1.0f); } else if (ExoPlayer.STATE_BUFFERING == playbackState) { state.setState(PlaybackState.STATE_BUFFERING, position, 1.0f); } else { if (player.getPlayerControl().isPlaying()) { state.setState(PlaybackState.STATE_PLAYING, position, 1.0f); } else { state.setState(PlaybackState.STATE_PAUSED, position, 1.0f); } } mediaSession.setPlaybackState(state.build()); }
private void assertMediaStateIs(@PlaybackStateCompat.State int expectedState) { PlaybackState state = rule.getActivity().getMediaController().getPlaybackState(); assertNotNull(state); assertThat( "MediaSession is not in the correct state", state.getState(), is(equalTo(expectedState))); }
public void updateMetadata(){ if(mediaController!=null&&mediaController.getPlaybackState()!=null){ currentlyPlaying = mediaController.getPlaybackState().getState() == PlaybackState.STATE_PLAYING; } if(meta==null)return; currentArt=meta.getBitmap(MediaMetadata.METADATA_KEY_ART); if(currentArt==null){ currentArt = meta.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART); } if(currentArt==null){ currentArt = meta.getBitmap(MediaMetadata.METADATA_KEY_DISPLAY_ICON); } currentArtist=meta.getString(MediaMetadata.METADATA_KEY_ARTIST); currentSong=meta.getString(MediaMetadata.METADATA_KEY_TITLE); if(currentSong==null){ currentSong=meta.getString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE); } currentAlbum=meta.getString(MediaMetadata.METADATA_KEY_ALBUM); if(currentArtist==null){ currentArtist = meta.getString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST); } if(currentArtist==null) { currentArtist = meta.getString(MediaMetadata.METADATA_KEY_AUTHOR); } if(currentArtist==null) { currentArtist = meta.getString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE); } if(currentArtist==null) { currentArtist = meta.getString(MediaMetadata.METADATA_KEY_WRITER); } if(currentArtist==null) { currentArtist = meta.getString(MediaMetadata.METADATA_KEY_COMPOSER); } if(currentArtist==null) currentArtist = ""; if(currentSong==null) currentSong = ""; if(currentAlbum==null) currentAlbum = ""; sendBroadcast(new Intent(MEDIA_UPDATE)); }
private MediaController pickController(List<MediaController> controllers){ for(int i=0;i<controllers.size();i++){ MediaController mc = controllers.get(i); if(mc!=null&&mc.getPlaybackState()!=null&& mc.getPlaybackState().getState()==PlaybackState.STATE_PLAYING){ return mc; } } if(controllers.size()>0) return controllers.get(0); return null; }
private void updatePlaybackState(int position) { PlaybackState.Builder stateBuilder = new PlaybackState.Builder() .setActions(getAvailableActions()); int state = PlaybackState.STATE_PLAYING; if (mPlaybackState == LeanbackPlaybackState.PAUSED) { state = PlaybackState.STATE_PAUSED; } stateBuilder.setState(state, position, 1.0f); mSession.setPlaybackState(stateBuilder.build()); }