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

Handle non-existent URL's #72

Open
juanpablofernandez opened this issue Nov 27, 2023 · 0 comments
Open

Handle non-existent URL's #72

juanpablofernandez opened this issue Nov 27, 2023 · 0 comments

Comments

@juanpablofernandez
Copy link

Is your feature request related to a problem? Please describe.
Devs should definetly check that the URL provided when creating an AudioItem is valid and can be played. But there remains a case where the url can be broken later on, or it was never available. When this happens in a QueuedAudioPlayer it stops playing, I think a better solution is to skip to the next AudioItem in the queue.

Describe the solution or feature you would like
I've been playing around with a solution for this, and came up with the following code. I placed it inside the handleAudioPlayerPlaybackEnd handler, but I'm not sure if that's the right approach.

        if let currentItem = audioManager.player.currentItem {
            let currentPath = URL(string: currentItem.getSourceUrl())!.path()
            let doesNotExist = !FileManager.default.fileExists(atPath: currentPath)
            if doesNotExist {
                print("File DOES NOT EXIST")
                switch data {
                case .failed:
                    let newIndex = audioManager.player.currentIndex + 1
                    try? audioManager.player.jumpToItem(atIndex: newIndex)
                case .skippedToPrevious:
                    let newIndex = audioManager.player.currentIndex - 1
                    try? audioManager.player.jumpToItem(atIndex: newIndex)
                default: break
                }
            }
        }

Describe alternatives you've considered
I have not thought of any alternatives, but any feedback on this is welcomed.

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

1 participant