Java – Android – MediaPlayer HTTP error handling

I am trying to create an Android application that collects various remote song links and plays them for users. The application uses Android mediaplayer, and each song link will be redirected to the stream URL processed and finally played by mediaplayer

However, some of these song links are actually redirects and provide HTTP 404 errors because they are unavailable. I wonder if there is any way to directly process / capture these HTTP errors immediately. So far, what mediaplayer has done is to send signals:

Error (1, - 2147483648)

... after trying to connect to the data source 10 times, I can capture it to notify users that the song is not available

Of course, it takes too much time for users to wait for 10 retries, so I want to know if there is a way to capture the first time when an HTTP error occurs in mediaplayer without checking the URL to mediaplayer before sending, or breaking and managing exceptions through a network proxy connected to mediaplayer

Mediaplayer gives 10 exceptions:

07-16 05:16:30.549: e / mediahttpconnection (16698): IOException: java.io.ioexception: HTTP response: 404

resolvent:

If the error pops up 10 times and an error is issued each time, I don't understand why a simple try catch loop doesn't work:

try {
    // download URL
} catch (IOException e) {
    // presumably an exception is thrown the first time it gets 404 so put the error handling code here
}

In addition, can I suggest using multithreading to download from the URL and using something like executorservice, which allows you to submit runnable classes to it and run them at the same time (that is, the download task of each video so that they can be downloaded at the same time)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>