Mike Lowery
Mike Lowery

Reputation: 2868

MediaPlayer throwing errors in Android 5.0 (Lollipop)

I've written a media app that streams MP3s using an HTTP connection. This has been working great on Android versions 2.x - 4.x but is now generating errors in 5.x. The app cycles through a playlist object containing MP3s, each having its own unique HTTP address. The first file streams fine, but the next file (doesn't matter which file) produces the following errors when prepareAsync() is called:

07-04 18:57:19.785     65-10860/? E/NuCachedSource2﹕ source returned error -1, 10 retries left
07-04 18:57:22.874     65-10860/? E/NuCachedSource2﹕ source returned error -1, 9 retries left
07-04 18:57:25.907     65-10860/? E/NuCachedSource2﹕ source returned error -1, 8 retries left
07-04 18:57:28.929     65-10860/? E/NuCachedSource2﹕ source returned error -1, 7 retries left
07-04 18:57:31.972     65-10860/? E/NuCachedSource2﹕ source returned error -1, 6 retries left
07-04 18:57:35.024     65-10860/? E/NuCachedSource2﹕ source returned error -1, 5 retries left
07-04 18:57:38.062     65-10860/? E/NuCachedSource2﹕ source returned error -1, 4 retries left
07-04 18:57:41.085     65-10860/? E/NuCachedSource2﹕ source returned error -1, 3 retries left
07-04 18:57:44.110     65-10860/? E/NuCachedSource2﹕ source returned error -1, 2 retries left
07-04 18:57:47.262     65-10860/? E/NuCachedSource2﹕ source returned error -1, 1 retries left
07-04 18:57:50.294     65-10860/? E/NuCachedSource2﹕ source returned error -1, 0 retries left
07-04 18:57:50.419     65-10857/? E/GenericSource﹕ Failed to init from data source!
07-04 18:57:50.428    9592-9758/net.kicksass.shootingstarbbs.streamstar E/MediaPlayer﹕ error (1, -2147483648)
07-04 18:57:50.429    9592-9592/net.kicksass.shootingstarbbs.streamstar E/MediaPlayer﹕ Error (1,-2147483648)

In general, the app calls MediaPlayer's setDataSource(url) followed by prepareAsync(), then waits for the onPreparedListener to fire after which start() is called to begin streaming. Upon streaming completion, it calls reset() and then setDataSource(url) where the process begins again.

Why is Lollipop's MediaPlayer throwing this error?

Upvotes: 3

Views: 4844

Answers (2)

Ramon
Ramon

Reputation: 121

I had this issue on lollipop as well. Spaces in the URL were causing this issue for me. I replaced the spaces with %20 and it works fine.

used to be: mPlayer.setDataSource(myUrl);
changed to: mPlayer.setDataSource(myUrl.replaceAll(" ","%20"));

Hope this helps for the once having this issue as well. The Encode trick didn't work for me but put me on the right track in solving this for me.

Upvotes: 1

Mike Lowery
Mike Lowery

Reputation: 2868

It looks like the setDataSource(string) method used to automatically encode a passed-in URL with previous versions of Android but no longer in v5.x. The errors were occurring because the web server was returning an HTTP 404 Not Found. When I encode the URL before passing it to setDataSource() it works.

To further confuse things, my app was inconsistently encoding the URL, so sometimes it worked and other times it did not.

Upvotes: 2

Related Questions