Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playNextInQueue not working for more than 2 items? #96

Open
hell001 opened this issue Sep 30, 2024 · 1 comment
Open

playNextInQueue not working for more than 2 items? #96

hell001 opened this issue Sep 30, 2024 · 1 comment

Comments

@hell001
Copy link

hell001 commented Sep 30, 2024

Maybe I'm doing something wrong but this seems like a basic enough example:

let items = [
        URL(string: "<link-to-file1>")!,
        URL(string: "<link-to-file2>")!,
	URL(string: "<link-to-file3>")!
]

then I have a button with the following action:

player.queue(urls: items) // player is AudioPlayer()

this plays file 1

I have another button that calls the following:

player.playNextInQueue()

this jumps to file 2

then I call (again)

player.playNextInQueue()

but this does nothing and file 2 continues playing

has this function not been tested/used much or am I using it wrong?


update 1:

so if I just queue the songs and let them play, they play correctly. if I queue the songs and skip to file 2, and let file 2 finish, it does NOT go on to file 3. so regardless of that second playNextInQueue call above, the issue happens when I call It the first time


update 2:

it seems that playNextInQueue calls this:

playerContext.setInternalState(to: .pendingNext)

which will make its way to calling processSource at some point, and in processSource it has this:

if playerContext.internalState == .pendingNext {
            let entry = entriesQueue.dequeue(type: .upcoming)
            playerContext.setInternalState(to: .waitingForData)
            setCurrentReading(entry: entry, startPlaying: true, shouldClearQueue: true)
            rendererContext.resetBuffers()
}

specifically, shouldClearQueue is set to true, so the queue is being emptied. changing it from true to false makes it work, but im not sure if this breaks any other functionality, so id prefer to wait to see what anyone has to say


update 3:

it seems the only other time the internal state is set to pendingNext is in the play(audioEntry: AudioEntry) function (someone double check me), which already clears the queue as shown below:

    private func play(audioEntry: AudioEntry) {
        // ... code ...
        serializationQueue.sync {
            clearQueue()
            entriesQueue.enqueue(item: audioEntry, type: .upcoming)
            playerContext.setInternalState(to: .pendingNext)
             // ... code ...
        }
         // ... code ...
    }

so it SEEMS that changing shouldClearQueue in the above update to false wouldn't break it since it already clears the queue (in fact it seems that in its current form the queue is being cleared twice - once in play() and the other in processSource)? however im not sure how this may impact functionality that may be added in the future, so again I will wait to hear back if its a simple boolean value change

@dimitris-c
Copy link
Owner

dimitris-c commented Oct 1, 2024

Hey, so the playNextInQueue accidentally made it to release, probably due to an incorrect merge.
It wasn't ready for production, apologies for this, will have to remove it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants