本文整理匯總了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());
}
}