本文整理汇总了Java中android.media.session.PlaybackState.getState方法的典型用法代码示例。如果您正苦于以下问题:Java PlaybackState.getState方法的具体用法?Java PlaybackState.getState怎么用?Java PlaybackState.getState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.session.PlaybackState
的用法示例。
在下文中一共展示了PlaybackState.getState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPlaybackState
import android.media.session.PlaybackState; //导入方法依赖的package包/类
public void setPlaybackState(PlaybackState playbackState) {
if (playbackItem == null) {
return;
}
playbackItem.updateAmountPlayed();
int state = playbackState.getState();
boolean isPlaying = state == PlaybackState.STATE_PLAYING;
if (isPlaying) {
Log.d(TAG, "Track playing");
postEvent(playbackItem.getTrack());
playbackItem.startPlaying();
notificationManager.updateNowPlaying(playbackItem.getTrack());
scheduleSubmission();
} else {
Log.d(TAG, String.format("Track paused (state %d)", state));
postEvent(Track.empty());
playbackItem.stopPlaying();
notificationManager.removeNowPlaying();
scrobbler.submit(playbackItem);
}
}
示例2: updatePlaybackState
import android.media.session.PlaybackState; //导入方法依赖的package包/类
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);
}
示例3: getView
import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MediaBrowser.MediaItem item = getItem(position);
int itemState = MediaItemViewHolder.STATE_NONE;
if (item.isPlayable()) {
itemState = MediaItemViewHolder.STATE_PLAYABLE;
MediaController controller = ((Activity) getContext()).getMediaController();
if (controller != null && controller.getMetadata() != null) {
String currentPlaying = controller.getMetadata().getDescription().getMediaId();
String musicId = MediaIDHelper.extractMusicIDFromMediaID(
item.getDescription().getMediaId());
if (currentPlaying != null && currentPlaying.equals(musicId)) {
PlaybackState pbState = controller.getPlaybackState();
if (pbState == null || pbState.getState() == PlaybackState.STATE_ERROR) {
itemState = MediaItemViewHolder.STATE_NONE;
} else if (pbState.getState() == PlaybackState.STATE_PLAYING) {
itemState = MediaItemViewHolder.STATE_PLAYING;
} else {
itemState = MediaItemViewHolder.STATE_PAUSED;
}
}
}
}
return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent,
item.getDescription(), itemState);
}
示例4: onClick
import android.media.session.PlaybackState; //导入方法依赖的package包/类
@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
import android.media.session.PlaybackState; //导入方法依赖的package包/类
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: getPlaybackState
import android.media.session.PlaybackState; //导入方法依赖的package包/类
private int getPlaybackState() {
Activity activity = getActivity();
if (activity != null) {
PlaybackState state = activity.getMediaController().getPlaybackState();
if (state != null) {
return state.getState();
} else {
return PlaybackState.STATE_NONE;
}
}
return PlaybackState.STATE_NONE;
}
示例7: onPlaybackStateChanged
import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
if (state.getState() != PlaybackState.STATE_NONE) {
updateProgress();
}
onStateChanged();
}
示例8: onPlaybackStateChanged
import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
// Update your UI to reflect the new state. Do not change media playback here.
if (DEBUG) Log.d(TAG, "Playback state changed: " + state.getState());
int nextState = state.getState();
if (nextState != PlaybackState.STATE_NONE) {
updateProgress();
}
onStateChanged();
}
示例9: getPlaybackState
import android.media.session.PlaybackState; //导入方法依赖的package包/类
private int getPlaybackState() {
Activity activity = getActivity();
if (activity != null) {
PlaybackState state = activity.getMediaController().getPlaybackState();
if (state != null) {
return state.getState();
} else {
return PlaybackState.STATE_NONE;
}
}
return PlaybackState.STATE_NONE;
}
示例10: onPlaybackStateChanged
import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(PlaybackState state) {
super.onPlaybackStateChanged(state);
StandardWidget.currentlyPlaying = state.getState() == PlaybackState.STATE_PLAYING;
updateMetadata();
sendBroadcast(new Intent(StandardWidget.WIDGET_UPDATE));
}
示例11: onPlaybackStateChanged
import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
super.onPlaybackStateChanged(state);
byte[] data = new byte[1];
data[0] = (byte)(state.getState() == PlaybackState.STATE_PLAYING ? 1 : 0);
mDevice.write(mediaPlayingCharac, data, MediaService.this);
}
示例12: isMediaPlaying
import android.media.session.PlaybackState; //导入方法依赖的package包/类
@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;
}
示例13: onPlaybackStateChanged
import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
if (state.getState() == PlaybackState.STATE_PLAYING
&& mCurrentPlaybackState == PlaybackState.STATE_PLAYING) {
startProgressAutomation();
setFadingEnabled(true);
} else if (state.getState() == PlaybackState.STATE_PLAYING) {
mCurrentPlaybackState = PlaybackState.STATE_PLAYING;
startProgressAutomation();
setFadingEnabled(true);
mPlayPauseAction.setIndex(PlayPauseAction.PAUSE);
mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlayPauseAction.PAUSE));
notifyChanged(mPlayPauseAction);
} else if (state.getState() == PlaybackState.STATE_PAUSED
&& mCurrentPlaybackState != PlaybackState.STATE_PAUSED) {
mCurrentPlaybackState = PlaybackState.STATE_PAUSED;
stopProgressAutomation();
setFadingEnabled(false);
mPlayPauseAction.setIndex(PlayPauseAction.PLAY);
mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlayPauseAction.PLAY));
notifyChanged(mPlayPauseAction);
}
int currentTime;
if (state.getState() == PlaybackState.STATE_PAUSED
|| state.getState() == PlaybackState.STATE_PLAYING) {
currentTime = mPlaybackControlsRow.getCurrentTime();
} else {
currentTime = (int) state.getPosition();
}
mPlaybackControlsRow.setCurrentTime(currentTime);
mPlaybackControlsRow.setBufferedProgress(currentTime + SIMULATED_BUFFERED_TIME);
}
示例14: onPlaybackStateChanged
import android.media.session.PlaybackState; //导入方法依赖的package包/类
@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);
}
示例15: onPlaybackStateChanged
import android.media.session.PlaybackState; //导入方法依赖的package包/类
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);
}