MediaHTTPConnection:readAt 3110239/32768 =>java.net.ProtocolException错误 [英] MediaHTTPConnection: readAt 3110239 / 32768 => java.net.ProtocolException Error
问题描述
我正在制作一个应用程序,它只是从URL播放歌曲.此URL将使用NanoHTTP创建.此URL只是设备ip和端口地址的组合.
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.
代码规范我刚刚收到此URL作为消息.一个我获取URL并将此URL提供给Media Player类.
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();
}
我的网址就像 http://192.168.1.160:8085/
问题
一切都很好,但是当我启动Media Player时却出现以下错误
Everything going fine but while I start Media Player than get following error
- W/MediaHTTPConnection:readAt 3110239/32768 => java.net.ProtocolException
,并且我的设备挂断并且设备没有响应.我也尝试使用mediaPlayer.prepareAsync(),mediaPlayer.prepare(FileDescriptor)处理此错误,但得到的结果相同.
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.
注意
此问题是特定于OS的,仅在5.0(LOLIPOP)OS中发生.
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.
推荐答案
对我来说,当两次使用数据源时,会发生此问题.我通过禁用缓存来修复它.问题是缓存保存了错误的长度或位置信息或其他内容.不知道为什么可能是因为压缩.
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.
我只对特定的mp3文件有此问题(我仍在研究为什么只影响这些文件).
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);
这篇关于MediaHTTPConnection:readAt 3110239/32768 =>java.net.ProtocolException错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!