How to handle when string URL being passed to VLCMedia doesn't work?
I'm currently passing a stream url that doesn't work (or a random one). VLCKit would push the view
and won't play anything (expected).
To handle that situation I'm implementing the following solution (which isn't beautiful but does the work for now)
mediaPlayer.media = VLCMedia(url: URL(string: mediaUrl)!)
mediaPlayer.play()
if (mediaPlayer.isPlaying == false) {
DispatchQueue.main.asyncAfter(deadline: .now() + 4.0) {
if (self.mediaPlayer.isPlaying == false) {
// do something
self.mediaPlayer.stop()
}
else {
print("placeholder")
}
}
}
The about snippet translates to: After calling the .play()
function, to the .isPlaying
method returns false
after 10 seconds, then do something
However, I'm obviously not sure about this solution. Is there any way that I can get an "error" to play with if the connection with the url that is being passed doesn't work (either because the connection times out or the string url isn't valid)?