本文整理匯總了Java中android.media.session.PlaybackState.STATE_STOPPED屬性的典型用法代碼示例。如果您正苦於以下問題:Java PlaybackState.STATE_STOPPED屬性的具體用法?Java PlaybackState.STATE_STOPPED怎麽用?Java PlaybackState.STATE_STOPPED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.media.session.PlaybackState
的用法示例。
在下文中一共展示了PlaybackState.STATE_STOPPED屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: stop
@Override
public void stop(boolean notifyListeners) {
mState = PlaybackState.STATE_STOPPED;
if (notifyListeners && mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
mCurrentPosition = getCurrentStreamPosition();
// Give up Audio focus
giveUpAudioFocus();
unregisterAudioNoisyReceiver();
// Relax all resources
relaxResources(true);
if (mWifiLock.isHeld()) {
mWifiLock.release();
}
}
示例2: 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;
}
}
示例3: shouldShowControls
/**
* 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() {
MediaController mediaController = getMediaController();
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;
}
}
示例4: onClick
@Override
public void onClick(View v) {
final int state = mCurrentState == null ?
PlaybackState.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);
}
getMediaController().getTransportControls().playFromMediaId(
mCurrentMetadata.getDescription().getMediaId(), null);
} else {
getMediaController().getTransportControls().pause();
}
}
示例5: 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());
}
示例6: 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);
}
示例7: 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();
}
}
示例8: stop
public void stop() {
Log.d ( TAG, "stop.." ) ;
playbackState = PlaybackState.STATE_STOPPED;
updatePlaybackState();
audioManager.abandonAudioFocus(this);
if (mediaPlayer != null) {
mediaPlayer.reset();
mediaPlayer.release();
}
}
示例9: stop
@Override
public void stop(boolean notifyListeners) {
mCastManager.removeVideoCastConsumer(mCastConsumer);
mState = PlaybackState.STATE_STOPPED;
if (notifyListeners && mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
}
示例10: onPlaybackStateChanged
private void onPlaybackStateChanged(PlaybackState state) {
LogHelper.d(TAG, "onPlaybackStateChanged ", state);
if (getActivity() == null) {
LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null," +
"this should not happen if the callback was properly unregistered. Ignoring.");
return;
}
if (state == null) {
return;
}
boolean enablePlay = false;
switch (state.getState()) {
case PlaybackState.STATE_PAUSED:
case PlaybackState.STATE_STOPPED:
enablePlay = true;
break;
case PlaybackState.STATE_ERROR:
LogHelper.e(TAG, "error playbackstate: ", state.getErrorMessage());
Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show();
break;
}
if (enablePlay) {
mPlayPause.setImageDrawable(
getActivity().getDrawable(R.drawable.ic_play_arrow_black_36dp));
} else {
mPlayPause.setImageDrawable(getActivity().getDrawable(R.drawable.ic_pause_black_36dp));
}
MediaController controller = getActivity().getMediaController();
String extraInfo = null;
if (controller != null && controller.getExtras() != null) {
String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
if (castName != null) {
extraInfo = getResources().getString(R.string.casting_to_device, castName);
}
}
setExtraInfo(extraInfo);
}
示例11: onPlaybackStateChanged
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
mPlaybackState = state;
LogHelper.d(TAG, "Received new playback state", state);
if (state.getState() == PlaybackState.STATE_STOPPED ||
state.getState() == PlaybackState.STATE_NONE) {
stopNotification();
} else {
Notification notification = createNotification();
if (notification != null) {
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
}
}
示例12: 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);
}
示例13: onClick
@Override
public void onClick(View v) {
final int state = mCurrentState == null ?
PlaybackState.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);
}
// ------------ CHANGE 5 - REMOVE FOLLOWING LINES FOR PLAYBACK ON A SERVICE
mPlaybackManager.play(mCurrentMetadata);
/* ------------ CHANGE 5 - UNCOMMENT FOLLOWING LINES FOR PLAYBACK ON A SERVICE
getMediaController().getTransportControls().playFromMediaId(
mCurrentMetadata.getDescription().getMediaId(), null);
// ------------ CHANGE 5 - END OF PLAYBACK ON A SERVICE SNIPPET */
} else {
// ------------ CHANGE 6 - REMOVE FOLLOWING LINES FOR PLAYBACK ON A SERVICE
mPlaybackManager.pause();
/* ------------ CHANGE 6 - UNCOMMENT FOLLOWING LINES FOR PLAYBACK ON A SERVICE
getMediaController().getTransportControls().pause();
// ------------ CHANGE 6 - END OF PLAYBACK ON A SERVICE SNIPPET */
}
}
示例14: stop
public void stop() {
mState = PlaybackState.STATE_STOPPED;
updatePlaybackState();
// Give up Audio focus
mAudioManager.abandonAudioFocus(this);
// Relax all resources
releaseMediaPlayer();
}
示例15: 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;
}
}