当前位置: 首页>>代码示例>>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;未经允许,请勿转载。