本文整理汇总了Java中android.media.session.MediaSession.getSessionToken方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSession.getSessionToken方法的具体用法?Java MediaSession.getSessionToken怎么用?Java MediaSession.getSessionToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.session.MediaSession
的用法示例。
在下文中一共展示了MediaSession.getSessionToken方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: initMediaSession
import android.media.session.MediaSession; //导入方法依赖的package包/类
private void initMediaSession() {
mMediaSession = new MediaSession( this, "Android Auto Audio Demo" );
mMediaSession.setActive( true );
mMediaSession.setCallback( mMediaSessionCallback );
mMediaSessionToken = mMediaSession.getSessionToken();
setSessionToken( mMediaSessionToken );
}
示例3: initMediaSessions
import android.media.session.MediaSession; //导入方法依赖的package包/类
private void initMediaSessions() {
mMediaPlayer = new MediaPlayer();
mSession = new MediaSession(getApplicationContext(), "simple player session");
mController =new MediaController(getApplicationContext(), mSession.getSessionToken());
mSession.setCallback(new MediaSession.Callback(){
@Override
public void onPlay() {
super.onPlay();
Log.e( "MediaPlayerService", "onPlay");
buildNotification( generateAction( android.R.drawable.ic_media_pause, "Pause", ACTION_PAUSE ) );
}
@Override
public void onPause() {
super.onPause();
Log.e( "MediaPlayerService", "onPause");
buildNotification(generateAction(android.R.drawable.ic_media_play, "Play", ACTION_PLAY));
}
@Override
public void onSkipToNext() {
super.onSkipToNext();
Log.e( "MediaPlayerService", "onSkipToNext");
//Change media here
buildNotification( generateAction( android.R.drawable.ic_media_pause, "Pause", ACTION_PAUSE ) );
}
@Override
public void onSkipToPrevious() {
super.onSkipToPrevious();
Log.e( "MediaPlayerService", "onSkipToPrevious");
//Change media here
buildNotification( generateAction( android.R.drawable.ic_media_pause, "Pause", ACTION_PAUSE ) );
}
@Override
public void onFastForward() {
super.onFastForward();
Log.e( "MediaPlayerService", "onFastForward");
//Manipulate current media here
}
@Override
public void onRewind() {
super.onRewind();
Log.e( "MediaPlayerService", "onRewind");
//Manipulate current media here
}
@Override
public void onStop() {
super.onStop();
Log.e( "MediaPlayerService", "onStop");
//Stop media player here
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel( 1 );
Intent intent = new Intent( getApplicationContext(), MediaPlayerService.class );
stopService( intent );
}
@Override
public void onSeekTo(long pos) {
super.onSeekTo(pos);
}
@Override
public void onSetRating(Rating rating) {
super.onSetRating(rating);
}
}
);
}