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


Java MediaSession.setPlaybackState方法代碼示例

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

示例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());
    }
}
 
開發者ID:bertrandmartel,項目名稱:youtubetv,代碼行數:20,代碼來源:WebviewUtils.java

示例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());
        }
    });
}
 
開發者ID:googlecodelabs,項目名稱:android-music-player,代碼行數:22,代碼來源:MusicService.java

示例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());
}
 
開發者ID:emuneee,項目名稱:MarshmallowFM,代碼行數:29,代碼來源:AudioPlayerService.java

示例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());
    }
}
 
開發者ID:lidox,項目名稱:reaction-test,代碼行數:43,代碼來源:GoNoGoGameView.java


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