本文整理匯總了Java中android.media.session.PlaybackState.STATE_BUFFERING屬性的典型用法代碼示例。如果您正苦於以下問題:Java PlaybackState.STATE_BUFFERING屬性的具體用法?Java PlaybackState.STATE_BUFFERING怎麽用?Java PlaybackState.STATE_BUFFERING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.media.session.PlaybackState
的用法示例。
在下文中一共展示了PlaybackState.STATE_BUFFERING屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getView
@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);
}
示例2: play
@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());
}
}
}
示例3: seekTo
@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);
}
}
}
示例4: 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;
}
}
示例5: connectToSession
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();
}
}
示例6: getView
@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);
}
示例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: isMediaPlaying
@Override
public boolean isMediaPlaying() {
if (mMediaController.getPlaybackState() == null) {
return false;
}
int state = mMediaController.getPlaybackState().getState();
return (state == PlaybackState.STATE_BUFFERING
|| state == PlaybackState.STATE_CONNECTING
|| state == PlaybackState.STATE_PLAYING
|| state == PlaybackState.STATE_FAST_FORWARDING
|| state == PlaybackState.STATE_REWINDING
|| state == PlaybackState.STATE_SKIPPING_TO_PREVIOUS
|| state == PlaybackState.STATE_SKIPPING_TO_NEXT);
}
示例9: 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);
}
}
示例10: updatePlaybackState
private void updatePlaybackState() {
int status = mCastManager.getPlaybackStatus();
int idleReason = mCastManager.getIdleReason();
LogHelper.d(TAG, "onRemoteMediaPlayerStatusUpdated ", status);
// Convert the remote playback states to media playback states.
switch (status) {
case MediaStatus.PLAYER_STATE_IDLE:
if (idleReason == MediaStatus.IDLE_REASON_FINISHED) {
if (mCallback != null) {
mCallback.onCompletion();
}
}
break;
case MediaStatus.PLAYER_STATE_BUFFERING:
mState = PlaybackState.STATE_BUFFERING;
if (mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
break;
case MediaStatus.PLAYER_STATE_PLAYING:
mState = PlaybackState.STATE_PLAYING;
updateMetadata();
if (mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
break;
case MediaStatus.PLAYER_STATE_PAUSED:
mState = PlaybackState.STATE_PAUSED;
updateMetadata();
if (mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
break;
default: // case unknown
LogHelper.d(TAG, "State default : ", status);
break;
}
}
示例11: configMediaPlayerState
/**
* Reconfigures MediaPlayer according to audio focus settings and
* starts/restarts it. This method starts/restarts the MediaPlayer
* respecting the current audio focus state. So if we have focus, it will
* play normally; if we don't have focus, it will either leave the
* MediaPlayer paused or set it to a low volume, depending on what is
* allowed by the current focus settings. This method assumes mPlayer !=
* null, so if you are calling it, you have to do so from a context where
* you are sure this is the case.
*/
private void configMediaPlayerState() {
LogHelper.d(TAG, "configMediaPlayerState. mAudioFocus=", mAudioFocus);
if (mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK) {
// If we don't have audio focus and can't duck, we have to pause,
if (mState == PlaybackState.STATE_PLAYING) {
pause();
}
} else { // we have audio focus:
if (mAudioFocus == AUDIO_NO_FOCUS_CAN_DUCK) {
mMediaPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK); // we'll be relatively quiet
} else {
if (mMediaPlayer != null) {
mMediaPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL); // we can be loud again
} // else do something for remote client.
}
// If we were playing when we lost focus, we need to resume playing.
if (mPlayOnFocusGain) {
if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
LogHelper.d(TAG,"configMediaPlayerState startMediaPlayer. seeking to ",
mCurrentPosition);
if (mCurrentPosition == mMediaPlayer.getCurrentPosition()) {
mMediaPlayer.start();
mState = PlaybackState.STATE_PLAYING;
} else {
mMediaPlayer.seekTo(mCurrentPosition);
mState = PlaybackState.STATE_BUFFERING;
}
}
mPlayOnFocusGain = false;
}
}
if (mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
}
示例12: onSeekComplete
/**
* Called when MediaPlayer has completed a seek
*
* @see OnSeekCompleteListener
*/
@Override
public void onSeekComplete(MediaPlayer mp) {
LogHelper.d(TAG, "onSeekComplete from MediaPlayer:", mp.getCurrentPosition());
mCurrentPosition = mp.getCurrentPosition();
if (mState == PlaybackState.STATE_BUFFERING) {
mMediaPlayer.start();
mState = PlaybackState.STATE_PLAYING;
}
if (mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
}
示例13: onPlaybackStateChanged
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
LogHelper.d(TAG, "onPlaybackStateChanged, state=", state);
if (mPlaybackFragment == null || state.getState() == PlaybackState.STATE_BUFFERING) {
return;
}
mPlaybackFragment.updatePlaybackState(state);
}
示例14: onPlayerStateChanged
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
switch (playbackState){
case PlaybackState.STATE_PLAYING:
mProgressWheel.setVisibility(GONE);
mDanmakuView.resume();
startUitimer();
hideSystemUI();
mPlayBtn.setOnCheckedChangeListener(null);
mPlayBtn.setChecked(false);
mPlayBtn.setOnCheckedChangeListener(this);
break;
case PlaybackState.STATE_PAUSED:
mPlayBtn.setOnCheckedChangeListener(null);
mPlayBtn.setChecked(true);
mPlayBtn.setOnCheckedChangeListener(this);
break;
case PlaybackState.STATE_BUFFERING:
mProgressWheel.setVisibility(VISIBLE);
break;
case PlaybackState.STATE_STOPPED:
break;
case PlaybackState.STATE_ERROR:
break;
default:
break;
}
}
示例15: onPlayerStateChanged
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
Timber.e("onPlayerStateChanged: playWhenReady = " + String.valueOf(playWhenReady)
+ " playbackState = " + playbackState);
switch (playbackState) {
case PlaybackState.STATE_PLAYING:
//初始化播放點擊事件並設置總時長
initPlayVideo();
Timber.e("播放狀態: 準備 playing");
break;
case PlaybackState.STATE_BUFFERING:
Timber.e("播放狀態: 緩存完成 playing");
break;
case PlaybackState.STATE_CONNECTING:
Timber.e("播放狀態: 連接 CONNECTING");
break;
case PlaybackState.STATE_ERROR://錯誤
Timber.e("播放狀態: 錯誤 STATE_ERROR");
startPlay.setBackgroundColor(Color.WHITE);
ToastUtil.showShort("播放錯誤");
break;
case PlaybackState.STATE_FAST_FORWARDING:
Timber.e("播放狀態: 快速傳遞,播放完畢");
pausePlay();//暫停播放
break;
case PlaybackState.STATE_NONE:
Timber.e("播放狀態: 無 STATE_NONE");
break;
case PlaybackState.STATE_PAUSED:
Timber.e("播放狀態: 暫停 PAUSED");
break;
case PlaybackState.STATE_REWINDING:
Timber.e("播放狀態: 倒回 REWINDING");
break;
case PlaybackState.STATE_SKIPPING_TO_NEXT:
Timber.e("播放狀態: 跳到下一個");
break;
case PlaybackState.STATE_SKIPPING_TO_PREVIOUS:
Timber.e("播放狀態: 跳到上一個");
break;
case PlaybackState.STATE_SKIPPING_TO_QUEUE_ITEM:
Timber.e("播放狀態: 跳到指定的Item");
break;
case PlaybackState.STATE_STOPPED:
Timber.e("播放狀態: 停止的 STATE_STOPPED");
break;
}
}