本文整理汇总了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();
}
}