當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaSession.getSessionToken方法代碼示例

本文整理匯總了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());
}
 
開發者ID:emuneee,項目名稱:MarshmallowFM,代碼行數:29,代碼來源:AudioPlayerService.java

示例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 );
}
 
開發者ID:Lakkichand,項目名稱:AndroidDemoProjects,代碼行數:9,代碼來源:AutoMediaBrowserService.java

示例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);
        }
        }
    );
}
 
開發者ID:Lakkichand,項目名稱:AndroidDemoProjects,代碼行數:75,代碼來源:MediaPlayerService.java


注:本文中的android.media.session.MediaSession.getSessionToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。