用
logcat -s MediaPlaybackService
來看..可以看到,Music 在background 繼續播放,在收到 AudioManger 的通之後,才會停止:
                case FOCUSCHANGE:
                    // This code is here so we can better synchronize it with the code that
                    // handles fade-in
                    // AudioFocus is a new feature: focus updates are made verbose on purpose
                    switch (msg.arg1) {
                        case AudioManager.AUDIOFOCUS_LOSS:
                            Log.v(LOGTAG, "AudioFocus: received AUDIOFOCUS_LOSS");
                            if(isPlaying()) {
                                mPausedByTransientLossOfFocus = false;
                            }
                            pause();
                            break;
但是其他的 event: AUDIOFOCUS_GAIN, AUDIOFOCUSE_LOSS_TRANSIENT 都沒收到。
從 code 來看, 這兩個 message 應該是在有電話進來的時候會有,先收到 LOSS_TRANSIENT。
等電話掛斷後,收到 AUDIOFOCUS_GAIN。
另外,BroadcastReceiver( ) 也有針對 play, pause, next, prev 的 cmd 操作,可以把 debugLog 修改一下:
            Log.v(LOGTAG,"mIntentReceiver.onReceive " + action + " / " + cmd);
這個 command 是給 Music app 自己用的 - 因為宣告成 class private variable.
上面的messasge 出來的是:
V/MediaPlaybackService( 2610): mIntentReceiver.onReceive com.android.music.musicservicecommand / pause
V/MediaPlaybackService( 2610): pause
V/MediaPlaybackService( 2610): mIntentReceiver.onReceive com.android.music.musicservicecommand / pause
V/MediaPlaybackService( 2610): pause
V/MediaPlaybackService( 2610): onStartCommand
在 framework 裡找到用這個command(Intent) 的 code:
frameworks/base/core/java/android/widget/VideoView.java:
    private void openVideo() {
        if (mUri == null || mSurfaceHolder == null) {
            // not ready for playback just yet, will try again later
            return;
        }
        // Tell the music playback service to pause
        // TODO: these constants need to be published somewhere in the framework.
        Intent i = new Intent("com.android.music.musicservicecommand");
        i.putExtra("command", "pause");
        mContext.sendBroadcast(i);
沒有留言:
張貼留言