本文整理匯總了Java中android.media.session.PlaybackState.PLAYBACK_POSITION_UNKNOWN屬性的典型用法代碼示例。如果您正苦於以下問題:Java PlaybackState.PLAYBACK_POSITION_UNKNOWN屬性的具體用法?Java PlaybackState.PLAYBACK_POSITION_UNKNOWN怎麽用?Java PlaybackState.PLAYBACK_POSITION_UNKNOWN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.media.session.PlaybackState
的用法示例。
在下文中一共展示了PlaybackState.PLAYBACK_POSITION_UNKNOWN屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updatePlaybackState
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().isAudioPaused() ? 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());
}
示例2: updatePlaybackState
/**
* Update the current media player state, optionally showing an error message.
*
* @param error if not null, error message to present to the user.
*/
private void updatePlaybackState(String error) {
LogHelper.d(TAG, "updatePlaybackState, playback state=" + mPlayback.getState());
long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN;
if (mPlayback != null && mPlayback.isConnected()) {
position = mPlayback.getCurrentStreamPosition();
}
PlaybackState.Builder stateBuilder = new PlaybackState.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 = PlaybackState.STATE_ERROR;
}
stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime());
// Set the activeQueueItemId if the current index is valid.
if (QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) {
MediaSession.QueueItem item = mPlayingQueue.get(mCurrentIndexOnQueue);
stateBuilder.setActiveQueueItemId(item.getQueueId());
}
mSession.setPlaybackState(stateBuilder.build());
if (state == PlaybackState.STATE_PLAYING || state == PlaybackState.STATE_PAUSED) {
mMediaNotificationManager.startNotification();
}
}