Skip to content

Handle non-existent URL's #72

@juanpablofernandez

Description

@juanpablofernandez

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions