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

Commit 0d908768 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

Fix MediaFocusControl index management for PlayerRecord

When updating the PlayerRecord stack on playstate changes and
 media button event receiver registrations, evaluate the index
 of the stack entry to remove against the index of the last playing
 entry as this index was valid before the entry was removed.
 This affects the insertion index.

Change-Id: Iec58d2df6bcbd8f55925e9e0f9d48f698f7cf4e5
parent 2e9c300b
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -1250,8 +1250,6 @@ public class MediaFocusControl implements OnFinished {
                }
                if (prse.hasMatchingMediaButtonIntent(mediaIntent)) {
                    inStackIndex = index;
                    // found it, ok to stop here
                    break;
                }
            }

@@ -1272,7 +1270,11 @@ public class MediaFocusControl implements OnFinished {
                        mPRStack.push(prse);
                    } else {
                        // and put it after the ones with active playback
                        if (inStackIndex > lastPlayingIndex) {
                            mPRStack.add(lastPlayingIndex, prse);
                        } else {
                            mPRStack.add(lastPlayingIndex - 1, prse);
                        }
                    }
                }
            }
@@ -2151,13 +2153,13 @@ public class MediaFocusControl implements OnFinished {
                // of this RemoteControlClient (note that it may not be in the stack)
                for (int index = mPRStack.size()-1; index >= 0; index--) {
                    prse = mPRStack.elementAt(index);
                    if (prse.isPlaybackActive()) {
                        lastPlayingIndex = index;
                    }
                    if (prse.getRccId() == rccId) {
                        inStackIndex = index;
                        prse.mPlaybackState = newState;
                    }
                    if (prse.isPlaybackActive()) {
                        lastPlayingIndex = index;
                    }
                }

                if (inStackIndex != -1) {
@@ -2177,7 +2179,11 @@ public class MediaFocusControl implements OnFinished {
                            mPRStack.push(prse);
                        } else {
                            // and put it after the ones with active playback
                            if (inStackIndex > lastPlayingIndex) {
                                mPRStack.add(lastPlayingIndex, prse);
                            } else {
                                mPRStack.add(lastPlayingIndex - 1, prse);
                            }
                        }
                    }