Q:

Media Player failing in onPrepare

I have looked up all the related questions about the error Prepare failed.: status=0x1. The code that I'm using is this:
MediaPlayer mediaPlayer = new MediaPlayer();
                    mediaPlayer.setDataSource(ChatActivity.this, Uri.parse(url));
                    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    mediaPlayer.setVolume(1, 1);
                    mediaPlayer.prepare();
                    mediaPlayer.start();

The URL is an actual link to an audio in Firebase. The funny thing is that I've written this exact same code in a whole new Android Proyect with just a button that triggers this code and it works perfectly, but in the previous app it doesn't. I have in both proyects the Internet permission in the manifest. Do you guys know what is going on?
Here's the log on the proyect that doesn't work the media player:
09-08 23:36:17.535 3265-3369/techluthiers.meetstream E/MediaHTTPConnectionEx: MediaHTTPConnectionEx contructor
09-08 23:36:17.536 3265-3281/techluthiers.meetstream E/MediaHTTPConnectionEx: connect
09-08 23:36:17.537 3265-3281/techluthiers.meetstream E/MediaHTTPConnectionEx: disconnecting
09-08 23:36:17.537 3265-3281/techluthiers.meetstream E/MediaHTTPConnectionEx: disconnected
09-08 23:36:17.545 3265-3514/techluthiers.meetstream E/MediaHTTPConnectionEx: getMIMEType
09-08 23:36:17.545 3265-3514/techluthiers.meetstream E/MediaHTTPConnectionEx: [seekToEx] offset:0/mCurrentOffset:-1
09-08 23:36:17.547 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: proxy null port 0
09-08 23:36:17.548 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [seekToEx] HTTP header =>User-Agent: Player/LG Player 1.0 for Android 5.0.1 (stagefright alternative)
09-08 23:36:17.548 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [seekToEx] include Range: bytes= 0-
09-08 23:36:17.548 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [seekToEx] HTTP header =>Range: bytes=0-
09-08 23:36:17.802 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response code] STATUS CODE:200
09-08 23:36:17.802 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] null: [HTTP/1.1 200 OK]
09-08 23:36:17.802 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] Accept-Ranges: [bytes]
09-08 23:36:17.802 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] Alt-Svc: [quic=":443"; ma=2592000; v="36,35,34,33,32"]
09-08 23:36:17.802 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] Cache-Control: [private, max-age=0]
09-08 23:36:17.802 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] Content-Length: [0]
09-08 23:36:17.802 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] Content-Type: [audio/mp3]
09-08 23:36:17.802 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] Date: [Fri, 09 Sep 2016 05:36:18 GMT]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] ETag: ["df9b0a0ba77691dd6a24b39bd0ca9a30"]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] Expires: [Fri, 09 Sep 2016 05:36:18 GMT]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] Last-Modified: [Thu, 08 Sep 2016 21:18:04 GMT]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] Server: [UploadServer]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] X-Android-Received-Millis: [1473399377793]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] X-Android-Response-Source: [CONDITIONAL_CACHE 304]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] X-Android-Sent-Millis: [1473399377554]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] x-goog-generation: [1473369484922000]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] x-goog-hash: [crc32c=MkV9EA==, md5=35sKC6d2kd1qJLOb0MqaMA==]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] x-goog-meta-firebaseStorageDownloadTokens: [68848b58-1dac-4796-9377-0c40bf8a4018]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] x-goog-metageneration: [1]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] x-goog-storage-class: [STANDARD]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] x-goog-stored-content-encoding: [identity]
09-08 23:36:17.803 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] x-goog-stored-content-length: [62815]
09-08 23:36:17.804 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [response header] X-GUploader-UploadID: [AEnB2Urmyp8htgAAuaqc63aoFuQgTDFzSmKow6zvFADzpJxdpQ0F44sFzsHwV-nkjBvA44a9psp4zqw4IpiKrIhRD_9nf-NfIQ]
09-08 23:36:17.804 3265-3514/techluthiers.meetstream D/MediaHTTPConnectionEx: [ResponseMessage]:OK
09-08 23:36:17.804 3265-3514/techluthiers.meetstream I/MediaHTTPConnectionEx: [200 OK] mTotalSize: 0
09-08 23:36:17.866 3265-3281/techluthiers.meetstream E/MediaHTTPConnectionEx: getUri

As you can see on the last three lines, I'm getting a value of 0 for the total size of the file, while the other proyet it has this line:
09-08 23:32:54.159 1862-1879/com.example.master.mypplication I/MediaHTTPConnectionEx: [200 OK] mTotalSize: 62815
I've noticed that if I put the media player on the very beginning before the user has loged in with Firebase it works, then when I put the same logic inside a onClick of a button, after the user has logged in the media player works, but only once. Could it be that Firebase kind of blocks the MediaHTTPConnectionEx after the first time? It's a very weird behaviour

A:

Try ExoPlayer: https://google.github.io/ExoPlayer/guide.html. It provides more  flexibility in configuring the HTTP connection (see http://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer/upstream/UriDataSource.html) which may be useful.

