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