Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaHTTPConnection: readAt 3110239 / 32768 => java.net.ProtocolException Error

Tags:

java

android

I have making one Application which is just play song from a URL.This url will be Created using NanoHTTP.This URL is nothing but combination of Device ip and Port Address.

Code Specification I have just Receive this URL as Message.One i Get URL and Provide this URL to Media Player class.

  try {

                if (mediaPlayer != null) {
                    mediaPlayer.stop();
                    mediaPlayer.reset();
                    mediaPlayer.release();
                    mediaPlayer = null;
                }
                if (handler != null) {
                    handler.removeCallbacks(notification);

                }
                mediaPlayer = new MediaPlayer();
                mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                // String url =  URLEncoder.encode(commandHelper.getSongDetails().getSongURL(), "UTF-8");
                String url = commandHelper.getSongDetails().getSongURL();
                Log.e("Tag", "Receiving Url  Data ::" + url);// Song URL ::: http://192.168.1.160:8085/
                mediaPlayer.setDataSource(url);
                mediaPlayer.prepare();
                mediaPlayer.start();

            } catch (IOException e) {

                DebugLog.e("Value ::" + e.getMessage());
                e.printStackTrace();
            }

and My url is like http://192.168.1.160:8085/

Issue

Everything going fine but while I start Media Player than get following error

  • W/MediaHTTPConnection: readAt 3110239 / 32768 => java.net.ProtocolException

and Also my Device Hanging UP and Device is not Responding. I have also try mediaPlayer.prepareAsync(),mediaPlayer.prepare(FileDescriptor) for handle this error but I get same result.

Note

This issue is OS Specific it's Only happend in 5.0(LOLIPOP) OS.

Please help me if any one have proper solution about this problem.i Hardly try to solve this problem but i getting same error.so please help to solve this issue.

like image 274
Chirag Solanki Avatar asked Nov 06 '15 14:11

Chirag Solanki


2 Answers

For me this problem was happening when a data source was used twice. I fixed it by disabling caching. The problem was that caching was saving bad length or position info or something. Not sure why maybe because of compression.

I only had this problem on particular mp3 files(I'm still researching why only these files were affected).

Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "audio/mp3"); // change content type if necessary
headers.put("Accept-Ranges", "bytes");
headers.put("Status", "206");
headers.put("Cache-control", "no-cache");
Uri uri = Uri.parse(yourContentUrl);
player.setDataSource(getApplicationContext(), uri, headers);
like image 141
Kahea Hendrickson Avatar answered Nov 06 '22 23:11

Kahea Hendrickson


It's link to the source (and the OS).

I found an explication for my case : codec MPEG-4 ODSM, MPEG-4 SDSM.
With another source (only H.264, AAC), it's working.

Linked question : Android Marshmallow "Can't play this video" error
Formats supported by Android : http://developer.android.com/guide/appendix/media-formats.html

So the solution is to try another source or to re-encode you media.

like image 37
Julien Malige Avatar answered Nov 06 '22 21:11

Julien Malige