三星大媒体播放器插口异常 [英] Media Player socket exception in Samsung Grand
问题描述
我们正在通过本地代理服务器播放媒体。一切都正常,直到新的三星大的设备。在这个特定的设备,我们得到一个套接字异常如下:
we are playing media through a local proxy server. Everything was fine till the new Samsung Grand device. In that specific device we are getting a Socket exception as following:
4-04 17:55:35.646: W/System.err(15187): java.net.SocketException: sendto failed: ECONNRESET (Connection reset by peer)
04-04 17:55:35.646: W/System.err(15187): at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:506)
04-04 17:55:35.646: W/System.err(15187): at libcore.io.IoBridge.sendto(IoBridge.java:475)
04-04 17:55:35.646: W/System.err(15187): at java.net.PlainSocketImpl.write(PlainSocketImpl.java:507)
04-04 17:55:35.656: W/System.err(15187): at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
04-04 17:55:35.656: W/System.err(15187): at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269)
04-04 17:55:35.656: W/System.err(15187): at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185)
04-04 17:55:35.656: W/System.err(15187): at java.io.BufferedOutputStream.write(BufferedOutputStream.java:139)
04-04 17:55:35.656: W/System.err(15187): at com.ganeshane.music.gslib.comp.security.SecurityManager$EncryptDecryptAgent.decryptStreamWithHeaderAndFlush(SecurityManager.java:192)
04-04 17:55:35.656: W/System.err(15187): at com.ganeshane.music.gslib.comp.player.ProxyMediaPlayer$LocalFileServer.handleGetRequest(ProxyMediaPlayer.java:315)
04-04 17:55:35.656: W/System.err(15187): at com.ganeshane.music.gslib.comp.player.ProxyMediaPlayer$LocalFileServer.run(ProxyMediaPlayer.java:291)
04-04 17:55:35.656: W/System.err(15187): Caused by: libcore.io.ErrnoException: sendto failed: ECONNRESET (Connection reset by peer)
04-04 17:55:35.666: W/System.err(15187): at libcore.io.Posix.sendtoBytes(Native Method)
04-04 17:55:35.666: W/System.err(15187): at libcore.io.Posix.sendto(Posix.java:146)
04-04 17:55:35.666: W/System.err(15187): at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
04-04 17:55:35.666: W/System.err(15187): at libcore.io.IoBridge.sendto(IoBridge.java:473)
04-04 17:55:35.666: W/System.err(15187): ... 8 more
我们的获取和头部头是:
Our get and head headers are:
HEAD = "HTTP/1.1 200 OK\r\n" + Date + "\r\n"
+ "Last-Modified: Mon, 19 Jan 20013 12:51:42 GMT\r\n"
+ "Connection: Keep-Alive\r\n"
+ "Content-Type: audio/mpeg\r\n"
+ "Accept-Ranges: bytes\r\n"
+ "Server: Apache/2.2.9\r\n" + "Content-Length: "
+ fileLength + "\r\n" + "\r\n";
GET = "HTTP/1.1 200 OK\r\n" + Date + "\r\n"
+ "Last-Modified: Mon, 19 Jan 20013 12:51:42 GMT\r\n"
+ "Connection: Keep-Alive\r\n"
+ "Content-Type: audio/mpeg\r\n"
+ "Accept-Ranges: bytes\r\n"
+ "Server: Apache/2.2.9\r\n" + "Content-Length: "
+ fileLength + "\r\n" + "\r\n";
任何帮助将AP preciated。
Any help will be appreciated.
推荐答案
所以,我的解决办法是加密的MP3文件,而应适用于其他用途。我所面临的唯一问题是寻求缓冲时,是不完整的。我相信有一定的范围内结束请求,但我真的不在乎。它的工作原理时99.9%左右...
So, my solution was for Encrypted mp3 files, but should work for other uses. The only issue I have faced is seeking when buffering is not complete. I am sure there is some range end request, but I really don't care. It works 99.9% of the time so...
下面是相关的响应头的一部分,但你可以找到整个code在的https:/ /gist.github.com/frostymarvelous/26ac6cba11bf50e591a4
below is the relevant response headers part, but you can find the entire code at https://gist.github.com/frostymarvelous/26ac6cba11bf50e591a4
if (cbSkip > 0) {// It is a seek or skip request if there's a Range
// header
headers += "HTTP/1.1 206 Partial Content\r\n";
headers += "Content-Type: " + dataSource.getContentType() + "\r\n";
headers += "Accept-Ranges: bytes\r\n";
headers += "Content-Length: " + (fileSize - cbSkip) + "\r\n";
headers += "Content-Range: bytes " + cbSkip + "-" + (fileSize - 1) + "/" + fileSize + "\r\n";
headers += "Connection: Keep-Alive\r\n";
headers += "\r\n";
} else {
headers += "HTTP/1.1 200 OK\r\n";
headers += "Content-Type: " + dataSource.getContentType() + "\r\n";
headers += "Accept-Ranges: bytes\r\n";
headers += "Content-Length: " + fileSize + "\r\n";
headers += "Connection: Keep-Alive\r\n";
headers += "\r\n";
}
Log.i(TAG, "headers: " + headers);
OutputStream output = null;
byte[] buff = new byte[64 * 1024];
try {
output = new BufferedOutputStream(client.getOutputStream(), 32 * 1024);
output.write(headers.getBytes());
InputStream data = dataSource.getInputStream();
dataSource.skipFully(data, cbSkip);//try to skip as much as possible
// Loop as long as there's stuff to send and client has not closed
int cbRead;
while (!client.isClosed() && (cbRead = data.read(buff, 0, buff.length)) != -1) {
output.write(buff, 0, cbRead);
}
}
这篇关于三星大媒体播放器插口异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!