Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 26469ff3 authored by Sanket Agarwal's avatar Sanket Agarwal
Browse files

Forward in iPhone leads to play state being presisted as STOP.

When we press forward in iPhone (via AVRCP pass through or iPhone UI)
while connected over AVRCP we are resetting the state and expecting
AVRCP to give us a new play state when next song resumes. Turns out that
iPhone always keeps it state to be Playing.

The fix is to keep the mRemoteMediaPlayers a replica of what AVRCP says
so that when song resumes (from A2dpSinkService via startAvrcpUpdates)
we can restore the playing state.

Tested on iPhone and regression tested on Nexus 5X.

Bug: b/27768620
Change-Id: I8caf56072fa5743f28e1680860c161d3cd75b83c
parent e94f8eb8
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.media.MediaMetadata;
import android.media.browse.MediaBrowser.MediaItem;
import android.media.session.MediaController;
import android.media.session.MediaSession;
import android.media.session.PlaybackState;
import android.os.Bundle;
@@ -348,6 +349,21 @@ public class A2dpMediaBrowserService extends MediaBrowserService {

    private void msgTrack(PlaybackState pb, MediaMetadata mmd) {
        Log.d(TAG, "msgTrack: playback: " + pb + " mmd: " + mmd);
        // Log the current track position/content.
        MediaController controller = mSession.getController();
        PlaybackState prevPS = controller.getPlaybackState();
        MediaMetadata prevMM = controller.getMetadata();

        if (prevPS != null) {
            Log.d(TAG, "prevPS " + prevPS);
        }

        if (prevMM != null) {
            String title = prevMM.getString(MediaMetadata.METADATA_KEY_TITLE);
            long trackLen = prevMM.getLong(MediaMetadata.METADATA_KEY_DURATION);
            Log.d(TAG, "prev MM title " + title + " track len " + trackLen);
        }

        if (mmd != null) {
            Log.d(TAG, "msgTrack() mmd " + mmd.getDescription());
            mSession.setMetadata(mmd);
+4 −3
Original line number Diff line number Diff line
@@ -547,10 +547,11 @@ public class AvrcpControllerService extends ProfileService {
            case AvrcpControllerConstants.MESSAGE_STOP_METADATA_BROADCASTS:
                // Any messages hence forth about play pos/play status/song info will be ignored.
                if(mRemoteMediaPlayers != null) {
                    mRemoteMediaPlayers.getAddressedPlayer().mPlayStatus =
                            AvrcpControllerConstants.PLAY_STATUS_PAUSED;
                    // Mock the current state to *look like* it is paused. The remote play state is
                    // still cached in mRemoteMediaPlayers and will be restored when the
                    // startAvrcpUpdates is called again.
                    broadcastPlayBackStateChanged(AvrcpUtils.mapBtPlayStatustoPlayBackState
                            (mRemoteMediaPlayers.getAddressedPlayer().mPlayStatus,
                            ((byte) AvrcpControllerConstants.PLAY_STATUS_PAUSED,
                             mRemoteMediaPlayers.getAddressedPlayer().mPlayTime));
                }
                mBroadcastMetadata = false;