本文整理汇总了Java中android.media.session.PlaybackState.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java PlaybackState.Builder方法的具体用法?Java PlaybackState.Builder怎么用?Java PlaybackState.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.session.PlaybackState
的用法示例。
在下文中一共展示了PlaybackState.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateMediaSession
import android.media.session.PlaybackState; //导入方法依赖的package包/类
private void updateMediaSession(int state) {
MediaMetadata.Builder mediaBuilder = null;
Bitmap bitmap = null;
try {
URL url = new URL(mRadioIcon);
bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e) {
Log.e(TAG, "BitmapFactory.decodeStream", e);
}
mediaBuilder = new MediaMetadata.Builder();
mediaBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, mTitle);
if (bitmap != null) {
mediaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
}
mMediaSession.setMetadata(mediaBuilder.build());
PlaybackState.Builder stateBuilder = new PlaybackState.Builder();
stateBuilder.setState(state, 0, 1.0f);
mMediaSession.setPlaybackState(stateBuilder.build());
}
示例2: updatePlayState
import android.media.session.PlaybackState; //导入方法依赖的package包/类
private void updatePlayState() {
PlaybackState.Builder builder = new PlaybackState.Builder();
switch (App.MiamPlayer.getState()) {
case PLAY:
builder.setState(PlaybackState.STATE_PLAYING, App.MiamPlayer.getSongPosition(),
1.0f);
break;
case PAUSE:
builder.setState(PlaybackState.STATE_PAUSED, App.MiamPlayer.getSongPosition(),
1.0f);
break;
case STOP:
builder.setState(PlaybackState.STATE_STOPPED, 0, 1.0f);
break;
default:
break;
}
mMediaSession.setPlaybackState(builder.build());
}
示例3: updatePlayPauseState
import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
protected void updatePlayPauseState() {
EventBus.getDefault().post(new ToggleSubtitleEvent(mIsSubtitleEnabled));
EventBus.getDefault().post(new UpdatePlaybackStateEvent(isPlaying()));
if (mMediaSession != null) {
PlaybackState.Builder builder = new PlaybackState.Builder();
builder.setActions(isPlaying()
? PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PAUSE
: PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PLAY);
builder.setState(
isPlaying() ? PlaybackState.STATE_PLAYING : PlaybackState.STATE_PAUSED,
getCurrentTime(),
1.0f);
mMediaSession.setPlaybackState(builder.build());
}
}
示例4: setCustomAction
import android.media.session.PlaybackState; //导入方法依赖的package包/类
private void setCustomAction(PlaybackState.Builder stateBuilder) {
MediaMetadata currentMusic = getCurrentPlayingMusic();
if (currentMusic != null) {
// Set appropriate "Favorite" icon on Custom action:
String musicId = currentMusic.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
int favoriteIcon = R.drawable.ic_star_off;
if (mMusicProvider.isFavorite(musicId)) {
favoriteIcon = R.drawable.ic_star_on;
}
LogHelper.d(TAG, "updatePlaybackState, setting Favorite custom action of music ",
musicId, " current favorite=", mMusicProvider.isFavorite(musicId));
Bundle customActionExtras = new Bundle();
WearHelper.setShowCustomActionOnWear(customActionExtras, true);
stateBuilder.addCustomAction(new PlaybackState.CustomAction.Builder(
CUSTOM_ACTION_THUMBS_UP, getString(R.string.favorite), favoriteIcon)
.setExtras(customActionExtras)
.build());
}
}
示例5: updateMediaSession
import android.media.session.PlaybackState; //导入方法依赖的package包/类
public static void updateMediaSession(boolean updateMetadata,
MediaMetadata.Builder mediaBuilder,
final MediaSession mediaSession,
final int playbackState,
final long position,
final float speed) {
if (mediaSession.isActive()) {
if (updateMetadata) {
mediaSession.setMetadata(mediaBuilder.build());
}
PlaybackState.Builder stateBuilder = new PlaybackState.Builder();
stateBuilder.setState(playbackState,
position,
speed);
mediaSession.setPlaybackState(stateBuilder.build());
}
}
示例6: updatePlaybackState
import android.media.session.PlaybackState; //导入方法依赖的package包/类
private void updatePlaybackState(int playbackState) {
PlaybackState.Builder state = new PlaybackState.Builder();
long position = player.getCurrentPosition();
if (ExoPlayer.STATE_PREPARING == playbackState) {
state.setState(PlaybackState.STATE_CONNECTING, position, 1.0f);
} else if (ExoPlayer.STATE_BUFFERING == playbackState) {
state.setState(PlaybackState.STATE_BUFFERING, position, 1.0f);
} else {
if (player.getPlayerControl().isPlaying()) {
state.setState(PlaybackState.STATE_PLAYING, position, 1.0f);
} else {
state.setState(PlaybackState.STATE_PAUSED, position, 1.0f);
}
}
mediaSession.setPlaybackState(state.build());
}
示例7: updatePlaybackState
import android.media.session.PlaybackState; //导入方法依赖的package包/类
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());
}
示例8: updatePlaybackState
import android.media.session.PlaybackState; //导入方法依赖的package包/类
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());
}
示例9: setPlaybackState
import android.media.session.PlaybackState; //导入方法依赖的package包/类
@SuppressWarnings("WrongConstant")
private void setPlaybackState(int state) {
long currentPosition = getCurrentPositionLong();
PlaybackState.Builder stateBuilder = new PlaybackState.Builder()
.setActions(getAvailableActions(state))
.setState(PlaybackState.STATE_PLAYING, currentPosition, 0);
if (mSession != null) {
mSession.setPlaybackState(stateBuilder.build());
}
}
示例10: stopNowPlayingCard
import android.media.session.PlaybackState; //导入方法依赖的package包/类
/**
* set now playing card to stop
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void stopNowPlayingCard() {
if(mSession==null)
return;
if (DBG) Log.d(TAG, "stopNowPlayingCard");
PlaybackState.Builder stateBuilder = new PlaybackState.Builder()
.setActions(getAvailableActions());
stateBuilder.setState(PlaybackState.STATE_STOPPED, PlaybackState.PLAYBACK_POSITION_UNKNOWN, 1.0f);
mSession.setPlaybackState(stateBuilder.build());
}
示例11: newInstance
import android.media.session.PlaybackState; //导入方法依赖的package包/类
public static Object newInstance(int state, long position, long bufferedPosition, float speed, long actions, CharSequence errorMessage, long updateTime, List<Object> customActions, long activeItemId) {
PlaybackState.Builder stateObj = new PlaybackState.Builder();
stateObj.setState(state, position, speed, updateTime);
stateObj.setBufferedPosition(bufferedPosition);
stateObj.setActions(actions);
stateObj.setErrorMessage(errorMessage);
Iterator i$ = customActions.iterator();
while (i$.hasNext()) {
stateObj.addCustomAction((android.media.session.PlaybackState.CustomAction) i$.next());
}
stateObj.setActiveQueueItemId(activeItemId);
return stateObj.build();
}
示例12: setMediaSessionPlaybackState
import android.media.session.PlaybackState; //导入方法依赖的package包/类
private void setMediaSessionPlaybackState(boolean isPlaying) {
PlaybackState.Builder builder = new PlaybackState.Builder();
builder.setState(isPlaying ? PlaybackState.STATE_PLAYING : PlaybackState.STATE_STOPPED,
PlaybackState.PLAYBACK_POSITION_UNKNOWN,
isPlaying ? MEDIA_SESSION_PLAYING_SPEED : MEDIA_SESSION_STOPPED_SPEED);
mMediaSession.setPlaybackState(builder.build());
}
示例13: updatePlaybackState
import android.media.session.PlaybackState; //导入方法依赖的package包/类
private void updatePlaybackState() {
if (mCallback == null) {
return;
}
PlaybackState.Builder stateBuilder = new PlaybackState.Builder()
.setActions(getAvailableActions());
stateBuilder.setState(mState, getCurrentStreamPosition(), 1.0f, SystemClock.elapsedRealtime());
mCallback.onPlaybackStatusChanged(stateBuilder.build());
}
示例14: onEventMainThread
import android.media.session.PlaybackState; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public void onEventMainThread(StartPlaybackEvent event) {
togglePlayPause();
if (mMediaSession != null) {
PlaybackState.Builder builder = new PlaybackState.Builder();
builder.setActions(PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_PLAY_PAUSE);
builder.setState(PlaybackState.STATE_PLAYING, getCurrentTime(), 1.0f);
mMediaSession.setPlaybackState(builder.build());
}
}
示例15: onPlayerStateChanged
import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
PlaybackState.Builder stateBuilder = new PlaybackState.Builder();
stateBuilder.setState(playWhenReady ? PlaybackState.STATE_PLAYING : PlaybackState.STATE_PAUSED, player.getCurrentPosition(), 1.0f);
long actions = PlaybackState.ACTION_PLAY;
if (playWhenReady)
actions |= PlaybackState.ACTION_PAUSE;
stateBuilder.setActions(actions);
session.setPlaybackState(stateBuilder.build());
}