Java Code Examples for android.media.session.PlaybackState#STATE_ERROR
The following examples show how to use
android.media.session.PlaybackState#STATE_ERROR .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicPlayerActivity.java From android-music-player with Apache License 2.0 | 7 votes |
@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); }
Example 2
Source File: MusicPlayerActivity.java From android-music-player with Apache License 2.0 | 6 votes |
@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); }
Example 3
Source File: PlaybackControlBaseActivity.java From LyricHere with Apache License 2.0 | 6 votes |
/** * 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() { MediaControllerCompat mediaController = mMediaController; 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; } }
Example 4
Source File: MusicPlayerActivity.java From io2015-codelabs with Apache License 2.0 | 6 votes |
@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); }
Example 5
Source File: MusicPlayerActivity.java From io2015-codelabs with Apache License 2.0 | 6 votes |
@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); }
Example 6
Source File: MusicBrowserService.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private void updatePlaybackState(String error) { long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN; MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject(); if (playingMessageObject != null) { position = playingMessageObject.audioProgressSec * 1000; } PlaybackState.Builder stateBuilder = new PlaybackState.Builder().setActions(getAvailableActions()); int state; if (playingMessageObject == null) { state = PlaybackState.STATE_STOPPED; } else { if (MediaController.getInstance().isDownloadingCurrentMessage()) { state = PlaybackState.STATE_BUFFERING; } else { state = MediaController.getInstance().isMessagePaused() ? PlaybackState.STATE_PAUSED : PlaybackState.STATE_PLAYING; } } if (error != null) { stateBuilder.setErrorMessage(error); state = PlaybackState.STATE_ERROR; } stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime()); if (playingMessageObject != null) { stateBuilder.setActiveQueueItemId(MediaController.getInstance().getPlayingMessageObjectNum()); } else { stateBuilder.setActiveQueueItemId(0); } mediaSession.setPlaybackState(stateBuilder.build()); }
Example 7
Source File: MusicBrowserService.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private void updatePlaybackState(String error) { long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN; MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject(); if (playingMessageObject != null) { position = playingMessageObject.audioProgressSec * 1000; } PlaybackState.Builder stateBuilder = new PlaybackState.Builder().setActions(getAvailableActions()); int state; if (playingMessageObject == null) { state = PlaybackState.STATE_STOPPED; } else { if (MediaController.getInstance().isDownloadingCurrentMessage()) { state = PlaybackState.STATE_BUFFERING; } else { state = MediaController.getInstance().isMessagePaused() ? PlaybackState.STATE_PAUSED : PlaybackState.STATE_PLAYING; } } if (error != null) { stateBuilder.setErrorMessage(error); state = PlaybackState.STATE_ERROR; } stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime()); if (playingMessageObject != null) { stateBuilder.setActiveQueueItemId(MediaController.getInstance().getPlayingMessageObjectNum()); } else { stateBuilder.setActiveQueueItemId(0); } mediaSession.setPlaybackState(stateBuilder.build()); }
Example 8
Source File: MediaController2Lollipop.java From AcDisplay with GNU General Public License v2.0 | 5 votes |
@Nullable private MediaController pickBestMediaController( @NonNull List<MediaController> list) { int mediaControllerScore = -1; MediaController mediaController = null; for (MediaController mc : list) { if (mc == null) continue; int mcScore = 0; // Check for the current state PlaybackState state = mc.getPlaybackState(); if (state != null) { switch (state.getState()) { case PlaybackState.STATE_STOPPED: case PlaybackState.STATE_ERROR: break; default: mcScore++; break; } } if (mcScore > mediaControllerScore) { mediaControllerScore = mcScore; mediaController = mc; } } return mediaController; }
Example 9
Source File: MusicBrowserService.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private void updatePlaybackState(String error) { long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN; MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject(); if (playingMessageObject != null) { position = playingMessageObject.audioProgressSec * 1000L; } PlaybackState.Builder stateBuilder = new PlaybackState.Builder().setActions(getAvailableActions()); int state; if (playingMessageObject == null) { state = PlaybackState.STATE_STOPPED; } else { if (MediaController.getInstance().isDownloadingCurrentMessage()) { state = PlaybackState.STATE_BUFFERING; } else { state = MediaController.getInstance().isMessagePaused() ? PlaybackState.STATE_PAUSED : PlaybackState.STATE_PLAYING; } } if (error != null) { stateBuilder.setErrorMessage(error); state = PlaybackState.STATE_ERROR; } stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime()); if (playingMessageObject != null) { stateBuilder.setActiveQueueItemId(MediaController.getInstance().getPlayingMessageObjectNum()); } else { stateBuilder.setActiveQueueItemId(0); } mediaSession.setPlaybackState(stateBuilder.build()); }
Example 10
Source File: MusicBrowserService.java From Telegram with GNU General Public License v2.0 | 5 votes |
private void updatePlaybackState(String error) { long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN; MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject(); if (playingMessageObject != null) { position = playingMessageObject.audioProgressSec * 1000L; } PlaybackState.Builder stateBuilder = new PlaybackState.Builder().setActions(getAvailableActions()); int state; if (playingMessageObject == null) { state = PlaybackState.STATE_STOPPED; } else { if (MediaController.getInstance().isDownloadingCurrentMessage()) { state = PlaybackState.STATE_BUFFERING; } else { state = MediaController.getInstance().isMessagePaused() ? PlaybackState.STATE_PAUSED : PlaybackState.STATE_PLAYING; } } if (error != null) { stateBuilder.setErrorMessage(error); state = PlaybackState.STATE_ERROR; } stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime()); if (playingMessageObject != null) { stateBuilder.setActiveQueueItemId(MediaController.getInstance().getPlayingMessageObjectNum()); } else { stateBuilder.setActiveQueueItemId(0); } mediaSession.setPlaybackState(stateBuilder.build()); }