本文整理汇总了Java中android.media.session.MediaSession.setPlaybackState方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSession.setPlaybackState方法的具体用法?Java MediaSession.setPlaybackState怎么用?Java MediaSession.setPlaybackState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.session.MediaSession
的用法示例。
在下文中一共展示了MediaSession.setPlaybackState方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void onCreate() {
Log.d (TAG, "onCreate() " + this) ;
super.onCreate();
// Start a new MediaSession
mediaSession = new MediaSession(this, "MuziKarMusicService");
mediaSession.setCallback(mediaSessionCallback);
mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
setSessionToken(mediaSession.getSessionToken());
playbackControlEventBroadcastReceiver = new PlaybackControlEventBroadcastReceiver(this);
audioPlaybackHelper = new AudioPlaybackHelper(getApplicationContext(), new AudioPlaybackHelper.PlayStateChangeCallback() {
@Override
public void onPlaybackStatusChanged(PlaybackState state) {
mediaSession.setPlaybackState(state);
playbackControlEventBroadcastReceiver.update(audioPlaybackHelper.getCurrentMedia(), state, getSessionToken());
}
});
carConnectStatusBroadcastReceiver = new CarConnectStatusBroadcastReceiver( this ) ;
}
示例2: updateMediaSession
import android.media.session.MediaSession; //导入方法依赖的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());
}
}
示例3: onCreate
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
// Start a new MediaSession
mSession = new MediaSession(this, "MusicService");
mSession.setCallback(mCallback);
mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
setSessionToken(mSession.getSessionToken());
final MediaNotificationManager mediaNotificationManager = new MediaNotificationManager(this);
mPlayback = new PlaybackManager(this, new PlaybackManager.Callback() {
@Override
public void onPlaybackStatusChanged(PlaybackState state) {
mSession.setPlaybackState(state);
mediaNotificationManager.update(mPlayback.getCurrentMedia(), state, getSessionToken());
}
});
}
示例4: onCreate
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
mPlaybackState = new PlaybackState.Builder()
.setState(PlaybackState.STATE_NONE, 0, 1.0f)
.build();
// 1) set up media session and media session callback
mMediaSession = new MediaSession(this, SESSION_TAG);
mMediaSession.setCallback(mMediaSessionCallback);
mMediaSession.setActive(true);
mMediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
mMediaSession.setPlaybackState(mPlaybackState);
// 2) get instance to AudioManager
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
// 3) create our media player
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnBufferingUpdateListener(this);
// 4) create the media controller
mMediaController = new MediaController(this, mMediaSession.getSessionToken());
}
示例5: addAudioButtonClickListener
import android.media.session.MediaSession; //导入方法依赖的package包/类
private void addAudioButtonClickListener() {
try {
audioSession = new MediaSession(getApplicationContext(), "TAG");
audioSession.setCallback(new MediaSession.Callback() {
@Override
public boolean onMediaButtonEvent(final Intent mediaButtonIntent) {
String intentAction = mediaButtonIntent.getAction();
if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
KeyEvent event = mediaButtonIntent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event != null) {
int action = event.getAction();
if (action == KeyEvent.ACTION_DOWN) {
stopTimeOfGame_millis = event.getDownTime();
double usersReactionTime = (event.getDownTime() - startTimeOfGame_millis) / 1000.0;
UtilsRG.info("event.getDownTime(): " + usersReactionTime);
checkTouchEvent();
}
}
}
//int intentDelta = 50;
//stopTimeOfGame_millis = System.currentTimeMillis() - intentDelta;
//checkTouchEvent();
return super.onMediaButtonEvent(mediaButtonIntent);
}
});
PlaybackState state = new PlaybackState.Builder()
.setActions(PlaybackState.ACTION_PLAY_PAUSE)
.setState(PlaybackState.STATE_PLAYING, 0, 0, 0)
.build();
audioSession.setPlaybackState(state);
audioSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
audioSession.setActive(true);
} catch (Exception e) {
UtilsRG.info("could not addAudioButtonClickListener:" + e.getLocalizedMessage());
}
}