本文整理汇总了Java中android.media.session.PlaybackState.STATE_PAUSED属性的典型用法代码示例。如果您正苦于以下问题:Java PlaybackState.STATE_PAUSED属性的具体用法?Java PlaybackState.STATE_PAUSED怎么用?Java PlaybackState.STATE_PAUSED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.media.session.PlaybackState
的用法示例。
在下文中一共展示了PlaybackState.STATE_PAUSED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onClick
@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;
}
}
示例2: resumeToWatchedPositionIfNeeded
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);
}
示例3: updateProgress
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);
}
示例4: pause
@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();
}
示例5: updatePlaybackState
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);
}
示例6: updatePlaybackState
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());
}
示例7: 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());
}
示例8: updatePlaybackState
private void updatePlaybackState(PlaybackStateCompat state) {
mCurrentState = state;
if (state == null
|| state.getState() == PlaybackState.STATE_PAUSED
|| state.getState() == PlaybackState.STATE_STOPPED) {
mPlayPause.setImageDrawable(
ContextCompat.getDrawable(this, R.drawable.ic_play_arrow_black_36dp));
} else {
mPlayPause.setImageDrawable(
ContextCompat.getDrawable(this, R.drawable.ic_pause_black_36dp));
}
mPlaybackControls.setVisibility(state == null ? View.GONE : View.VISIBLE);
}
示例9: onClick
@Override
public void onClick(View v) {
final int state =
mCurrentState == null
? PlaybackStateCompat.STATE_NONE
: mCurrentState.getState();
if (state == PlaybackState.STATE_PAUSED
|| state == PlaybackState.STATE_STOPPED
|| state == PlaybackState.STATE_NONE) {
if (mCurrentMetadata == null) {
mCurrentMetadata =
MusicLibrary.getMetadata(
MusicPlayerActivity.this,
MusicLibrary.getMediaItems().get(0).getMediaId());
updateMetadata(mCurrentMetadata);
}
MediaControllerCompat.getMediaController(MusicPlayerActivity.this)
.getTransportControls()
.playFromMediaId(
mCurrentMetadata.getDescription().getMediaId(), null);
} else {
MediaControllerCompat.getMediaController(MusicPlayerActivity.this)
.getTransportControls()
.pause();
}
}
示例10: updatePlaybackState
private void updatePlaybackState() {
PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder()
.setActions(getAvailableActions());
int state = PlaybackStateCompat.STATE_PLAYING;
if (!mMediaPlayerGlue.isPlaying()) {
state = PlaybackState.STATE_PAUSED;
}
stateBuilder.setState(state, mMediaPlayerGlue.getCurrentPosition(), 1.0f);
mSession.setPlaybackState(stateBuilder.build());
}
示例11: isMediaPlaying
@Override
public boolean isMediaPlaying() {
PlaybackState playbackState = mMediaController.getPlaybackState();
if (playbackState == null) {
return false;
}
int state = playbackState.getState();
return state != PlaybackState.STATE_NONE && state != PlaybackState.STATE_CONNECTING
&& state != PlaybackState.STATE_PAUSED;
}
示例12: pause
public void pause() {
if (isPlaying()) {
mMediaPlayer.pause();
mAudioManager.abandonAudioFocus(this);
}
mState = PlaybackState.STATE_PAUSED;
updatePlaybackState();
}
示例13: updatePlaybackState
private void updatePlaybackState(PlaybackState state) {
mCurrentState = state;
if (state == null || state.getState() == PlaybackState.STATE_PAUSED ||
state.getState() == PlaybackState.STATE_STOPPED) {
mPlayPause.setImageDrawable(getDrawable(R.drawable.ic_play_arrow_black_36dp));
} else {
mPlayPause.setImageDrawable(getDrawable(R.drawable.ic_pause_black_36dp));
}
mPlaybackControls.setVisibility(state == null ? View.GONE : View.VISIBLE);
}
示例14: 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();
}
}
示例15: switchToPlayer
/**
* Helper to switch to a different Playback instance
* @param playback switch to this playback
*/
private void switchToPlayer(Playback playback, boolean resumePlaying) {
if (playback == null) {
throw new IllegalArgumentException("Playback cannot be null");
}
// suspend the current one.
int oldState = mPlayback.getState();
int pos = mPlayback.getCurrentStreamPosition();
String currentMediaId = mPlayback.getCurrentMediaId();
mPlayback.stop(false);
playback.setCallback(this);
playback.setCurrentStreamPosition(pos < 0 ? 0 : pos);
playback.setCurrentMediaId(currentMediaId);
playback.start();
// finally swap the instance
mPlayback = playback;
switch (oldState) {
case PlaybackState.STATE_BUFFERING:
case PlaybackState.STATE_CONNECTING:
case PlaybackState.STATE_PAUSED:
mPlayback.pause();
break;
case PlaybackState.STATE_PLAYING:
if (resumePlaying && QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) {
mPlayback.play(mPlayingQueue.get(mCurrentIndexOnQueue));
} else if (!resumePlaying) {
mPlayback.pause();
} else {
mPlayback.stop(true);
}
break;
case PlaybackState.STATE_NONE:
break;
default:
LogHelper.d(TAG, "Default called. Old state is ", oldState);
}
}