Skip to content

on Android TrackPlayer.move(from, to) was wrong #2562

Description

@andy380743909

Describe the Bug
I have a queue with ABCDE five songs.
after TrackPlayer.move(4, 1) on Android
from = 4
to = 1

I got a new queue:

0 E <- the E was inserted at 0
1 A
2 B
3 C
4 D

I compared the source code of iOS and Android:

/////// iOS

/**
     Move an item in the queue.

     - parameter fromIndex: The index of the item to be moved.
     - parameter toIndex: The index to move the item to. If the index is larger than the size of the queue, the item is moved to the end of the queue instead.
     - throws: AudioPlayerError.QueueError
     */
    public func moveItem(fromIndex: Int, toIndex: Int) throws {
        try synchronizeThrows {
            try throwIfQueueEmpty();
            try throwIfIndexInvalid(index: fromIndex, name: "fromIndex")
            try throwIfIndexInvalid(index: toIndex, name: "toIndex", max: Int.max)
            
            let item = items.remove(at: fromIndex)
            self.items.insert(item, at: min(items.count, toIndex));
            if (fromIndex == currentIndex) {
                currentIndex = toIndex;
            }
        }
    }

////// Android

/**
     * Move an item in the queue from one position to another.
     * @param fromIndex The index of the item ot move.
     * @param toIndex The index to move the item to. If the index is larger than the size of the queue, the item is moved to the end of the queue instead.
     */
    fun move(fromIndex: Int, toIndex: Int) {
        exoPlayer.moveMediaItem(fromIndex, toIndex)
        val item = queue[fromIndex]
        queue.removeAt(fromIndex)
        queue.add(max(0, min(items.size, if (toIndex > fromIndex) toIndex else toIndex - 1)), item)
    }

And Android have one more issue, after move, if I skip to next , the player played the song which was at the index before move

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions