本文整理汇总了Java中android.support.v4.media.session.PlaybackStateCompat.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java PlaybackStateCompat.Builder方法的具体用法?Java PlaybackStateCompat.Builder怎么用?Java PlaybackStateCompat.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.media.session.PlaybackStateCompat
的用法示例。
在下文中一共展示了PlaybackStateCompat.Builder方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void setState(int state) {
long position = 0;
if (mPlayer != null && mPlayer.isPlaying()) {
position = mPlayer.getCurrentPosition();
}
PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder();
builder.setState(state, position, 1.0f);
builder.setActions(
PlaybackStateCompat.ACTION_PLAY |
PlaybackStateCompat.ACTION_STOP |
PlaybackStateCompat.ACTION_REWIND |
PlaybackStateCompat.ACTION_FAST_FORWARD |
PlaybackStateCompat.ACTION_PAUSE |
PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
PlaybackStateCompat.ACTION_SKIP_TO_NEXT);
mMediaSession.setPlaybackState(builder.build());
}
示例2: updatePlaybackState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void updatePlaybackState(
@PlaybackStateCompat.State int state, long playbackActions, int position, int mediaId) {
PlaybackStateCompat.Builder builder =
new PlaybackStateCompat.Builder()
.setActions(playbackActions)
.setActiveQueueItemId(mediaId)
.setState(state, position, 1.0f);
mSession.setPlaybackState(builder.build());
}
示例3: updatePlaybackState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void updatePlaybackState() {
if (mCallback == null) {
return;
}
PlaybackStateCompat.Builder stateBuilder =
new PlaybackStateCompat.Builder().setActions(getAvailableActions());
stateBuilder.setState(
mState, getCurrentStreamPosition(), 1.0f, SystemClock.elapsedRealtime());
mCallback.onPlaybackStatusChanged(stateBuilder.build());
}
示例4: setPlaybackState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void setPlaybackState(int state) {
long currPosition = getCurrentPosition();
PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder()
.setActions(getAvailableActions(state));
stateBuilder.setState(state, currPosition, 1.0f);
mSession.setPlaybackState(stateBuilder.build());
}
示例5: updateMediaSession
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void updateMediaSession() {
if (!mMediaNotificationInfo.supportsPlayPause()) return;
if (mMediaSession == null) mMediaSession = createMediaSession();
try {
// Tell the MediaRouter about the session, so that Chrome can control the volume
// on the remote cast device (if any).
// Pre-MR1 versions of JB do not have the complete MediaRouter APIs,
// so getting the MediaRouter instance will throw an exception.
MediaRouter.getInstance(mContext).setMediaSessionCompat(mMediaSession);
} catch (NoSuchMethodError e) {
// Do nothing. Chrome can't be casting without a MediaRouter, so there is nothing
// to do here.
}
mMediaSession.setMetadata(createMetadata());
PlaybackStateCompat.Builder playbackStateBuilder =
new PlaybackStateCompat.Builder().setActions(computeMediaSessionActions());
if (mMediaNotificationInfo.isPaused) {
playbackStateBuilder.setState(PlaybackStateCompat.STATE_PAUSED,
PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f);
} else {
// If notification only supports stop, still pretend
playbackStateBuilder.setState(PlaybackStateCompat.STATE_PLAYING,
PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f);
}
mMediaSession.setPlaybackState(playbackStateBuilder.build());
}
示例6: updatePlaybackState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
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());
}
示例7: updatePlaybackState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
/**
* Update the current media player state, optionally showing an error message.
*/
public void updatePlaybackState() {
long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN;
if (mPlayback != null ) {
position = mPlayback.getCurrentPosition();
}
long actions =
PlaybackStateCompat.ACTION_PLAY_PAUSE |
PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
PlaybackStateCompat.ACTION_SKIP_TO_NEXT;
if (mPlayback != null && mPlayback.isPlaying()) {
actions |= PlaybackStateCompat.ACTION_PAUSE;
} else {
actions |= PlaybackStateCompat.ACTION_PLAY;
}
int state = mPlayback.getState();
//noinspection ResourceType
PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder()
.setActions(actions)
.setState(state, position, 1.0f, SystemClock.elapsedRealtime());
mMediaSession.setPlaybackState(stateBuilder.build());
Intent intent = new Intent("change-playback-state-event");
intent.putExtra("state", state);
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
}
示例8: updatePlaybackState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
public void updatePlaybackState(int state){
long position = playback.getPosition();
this.lastState=state;
if (state == PlaybackStateCompat.STATE_PLAYING ||
state == PlaybackStateCompat.STATE_PAUSED) {
serviceCallback.onNotificationRequired();
}
PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder()
.setActions(getAvailableActions())
.setState(state, position, 1.0f, SystemClock.elapsedRealtime());
serviceCallback.onPlaybackStateUpdated(builder.build());
}
示例9: setNewState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void setNewState(@PlaybackStateCompat.State int newPlayerState) {
mState = newPlayerState;
// Whether playback goes to completion, or whether it is stopped, the
// mCurrentMediaPlayedToCompletion is set to true.
if (mState == PlaybackStateCompat.STATE_STOPPED) {
mCurrentMediaPlayedToCompletion = true;
}
// Work around for MediaPlayer.getCurrentPosition() when it changes while not playing.
final long reportPosition;
if (mSeekWhileNotPlaying >= 0) {
reportPosition = mSeekWhileNotPlaying;
if (mState == PlaybackStateCompat.STATE_PLAYING) {
mSeekWhileNotPlaying = -1;
}
} else {
reportPosition = mMediaPlayer == null ? 0 : mMediaPlayer.getCurrentPosition();
}
final PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder();
stateBuilder.setActions(getAvailableActions());
stateBuilder.setState(mState,
reportPosition,
1.0f,
SystemClock.elapsedRealtime());
mPlaybackInfoListener.onPlaybackStateChange(stateBuilder.build());
}
示例10: updatePlaybackState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void updatePlaybackState(
@PlaybackStateCompat.State int state,
long position,
MediaDescriptionCompat description) {
PlaybackStateCompat.Builder builder =
new PlaybackStateCompat.Builder()
.setActions(AVAILABLE_MEDIA_ACTIONS)
.setActiveQueueItemId(Long.parseLong(description.getMediaId()))
.setState(state, position, 1.0f);
mSession.setPlaybackState(builder.build());
}
示例11: setNewState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void setNewState(@PlaybackStateCompat.State int newPlayerState) {
mState = newPlayerState;
// Whether playback goes to completion, or whether it is stopped, the
// mCurrentMediaPlayedToCompletion is set to true.
if (mState == PlaybackStateCompat.STATE_STOPPED) {
mCurrentMediaPlayedToCompletion = true;
}
// Work around for MediaPlayer.getCurrentPosition() when it changes while not playing.
final long reportPosition;
if (mSeekWhileNotPlaying >= 0) {
reportPosition = mSeekWhileNotPlaying;
if (mState == PlaybackStateCompat.STATE_PLAYING) {
mSeekWhileNotPlaying = -1;
}
} else {
reportPosition = mMediaPlayer == null ? 0 : mMediaPlayer.getCurrentPosition();
}
final PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder();
stateBuilder.setActions(getAvailableActions());
stateBuilder.setState(mState,
reportPosition,
1.0f,
SystemClock.elapsedRealtime());
mPlaybackInfoListener.onPlaybackStateChange(stateBuilder.build());
}
示例12: updatePlaybackState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
public void updatePlaybackState(int errorCode, String errorMsg) {
Log.d(TAG, "updatePlaybackState, playback state = " + mPlayback.getState());
long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN;
if (mPlayback != null && mPlayback.isConnected()) {
position = mPlayback.getCurrentStreamPosition();
}
long playbackActions = PlaybackStateCompat.ACTION_PLAY
| PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID;
if (mPlayback.isPlaying()) {
playbackActions |= PlaybackStateCompat.ACTION_PAUSE;
}
PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder().setActions(playbackActions);
int state = mPlayback.getState();
if (errorCode != -1 && errorMsg != null) {
builder.setErrorMessage(errorCode, errorMsg);
state = PlaybackStateCompat.STATE_ERROR;
}
builder.setState(state, position, SystemClock.elapsedRealtime());
MediaSessionCompat.QueueItem currentMedia = mQueueManager.getCurrentMedia();
if (currentMedia != null) {
builder.setActiveQueueItemId(currentMedia.getQueueId());
}
// mSession.setPlaybackState(builder.build());
mServiceCallback.onPlaybackStateUpdate(builder.build());
// if (state == PlaybackStateCompat.STATE_PLAYING ||
// state == PlaybackStateCompat.STATE_PAUSED) {
// mServiceCallback.onHandleNotification();
// }
//
}