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

Commit 9de8dfa7 authored by Marie Janssen's avatar Marie Janssen Committed by Andre Eisenbach
Browse files

AVRCP: Don't assume 0:00 on metadata change

When changing between apps, and changing between songs, the Media
framework sends us the position data before the metadata, so
setting it to 0 wipes out our position.

Fixes: 27745277
Change-Id: I2d309df424c8889928da9601b367d488bba89919
parent 7cb747c9
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ public final class Avrcp {
        mPlayStatusChangedNT = NOTIFICATION_TYPE_CHANGED;
        mTrackChangedNT = NOTIFICATION_TYPE_CHANGED;
        mTrackNumber = -1L;
        mCurrentPosMs = 0L;
        mCurrentPosMs = RemoteControlClient.PLAYBACK_POSITION_ALWAYS_UNKNOWN;
        mPlayStartTimeMs = -1L;
        mSongLengthMs = 0L;
        mPlaybackIntervalMs = 0L;
@@ -244,6 +244,7 @@ public final class Avrcp {
        @Override
        public void onClientPlaybackStateUpdate(int state) {
            // Should never be called with the existing code, but just in case
            if (DEBUG) Log.v(TAG, "RemoteControlDisplayer: Update playbackState state=" + state + " position=null");
            Handler handler = mLocalHandler.get();
            if (handler != null) {
                handler.obtainMessage(MSG_UPDATE_STATE, 0, state,
@@ -254,6 +255,7 @@ public final class Avrcp {
        @Override
        public void onClientPlaybackStateUpdate(int state, long stateChangeTimeMs,
                long currentPosMs, float speed) {
            if (DEBUG) Log.v(TAG, "RemoteControlDisplayer: Update playbackState state=" + state + " position=" + currentPosMs);
            Handler handler = mLocalHandler.get();
            if (handler != null) {
                handler.obtainMessage(MSG_UPDATE_STATE, 0, state,
@@ -727,7 +729,6 @@ public final class Avrcp {
            }

            if (mCurrentPosMs != RemoteControlClient.PLAYBACK_POSITION_ALWAYS_UNKNOWN) {
                mCurrentPosMs = 0L;
                if (mCurrentPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
                    mPlayStartTimeMs = SystemClock.elapsedRealtime();
                }
@@ -745,7 +746,6 @@ public final class Avrcp {

        mSongLengthMs = data.getLong(MediaMetadataRetriever.METADATA_KEY_DURATION,
                RemoteControlClient.PLAYBACK_POSITION_INVALID);
        Log.v(TAG, "duration=" + mSongLengthMs);
    }

    private void getRcFeatures(byte[] address, int features) {