Android HttpService-无法播放在线视频

Android HttpService-无法播放在线视频,android,servlets,webserver,video-streaming,httpservice,Android,Servlets,Webserver,Video Streaming,Httpservice,我正在使用HttpService向android设备和浏览器发送响应,以共享一些文件。这项服务在android设备上运行。一切正常,不包括视频文件。听在线音乐效果很好。但当我尝试观看在线视频时,我的WebService失败,错误如下: java.net.SocketException: sendto failed: EPIPE (Broken pipe) at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:506) at libc

我正在使用
HttpService
向android设备和浏览器发送响应,以共享一些文件。这项服务在android设备上运行。一切正常,不包括视频文件。听在线音乐效果很好。但当我尝试观看在线视频时,我的
WebService
失败,错误如下:

java.net.SocketException: sendto failed: EPIPE (Broken pipe)
at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:506)
at libcore.io.IoBridge.sendto(IoBridge.java:475)
at java.net.PlainSocketImpl.write(PlainSocketImpl.java:507)
at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269)
at org.apache.http.impl.io.AbstractSessionOutputBuffer.write(AbstractSessionOutputBuffer.java:109)
at org.apache.http.impl.io.ContentLengthOutputStream.write(ContentLengthOutputStream.java:113)
at org.apache.http.entity.FileEntity.writeTo(FileEntity.java:83)
at org.apache.http.impl.entity.EntitySerializer.serialize(EntitySerializer.java:97)
at org.apache.http.impl.AbstractHttpServerConnection.sendResponseEntity(AbstractHttpServerConnection.java:182)
at org.apache.http.protocol.HttpService.handleRequest(HttpService.java:209)
at com.test.communication.server.WebServer$1.run(WebServer.java:94)
at java.lang.Thread.run(Thread.java:856)
Caused by: libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe)
at libcore.io.Posix.sendtoBytes(Native Method)
at libcore.io.Posix.sendto(Posix.java:146)
at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
at libcore.io.IoBridge.sendto(IoBridge.java:473)
服务器端的一些代码片段:

WebServer.java

private BasicHttpProcessor httpproc = null;
private BasicHttpContext httpContext = null;
private HttpService httpService = null;
private HttpRequestHandlerRegistry registry = null;

public WebServer(Context context) {
    this.setContext(context);
    httpproc = new BasicHttpProcessor();
    httpContext = new BasicHttpContext();       
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());
    httpService = new HttpService(httpproc,
        new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());        
    registry = new HttpRequestHandlerRegistry(); 
    registry.register(MOBILE_BASE_PATTERN, new MobileFileBrowseHandler(context));

    httpService.setHandlerResolver(registry);
}

public void runServer() {
    new Thread(new Runnable() {         
        public void run() {
            try {                   
                serverSocket = new ServerSocket(Constants.DEFAULT_SERVER_PORT);     
                serverSocket.setReuseAddress(true);                     
                        while (RUNNING) {                               
                            try {                                   
                                final Socket socket = serverSocket.accept();                                    
                                DefaultHttpServerConnection serverConnection = new DefaultHttpServerConnection();                                                                       
                                serverConnection.bind(socket, new BasicHttpParams());

                                httpService.handleRequest(serverConnection, httpContext); //ERROR UCCURS!!!     
                                serverConnection.shutdown();
                            } catch (IOException e) {
                                e.printStackTrace();
                            } catch (HttpException e) {
                                e.printStackTrace();
                            }
                        }           
                serverSocket.close();                   
            } catch (SocketException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }       
            RUNNING = false;
        }
    }).start();
}
public void handle(HttpRequest request, HttpResponse response,
        HttpContext context) throws HttpException, IOException {
    HttpEntity entity = null;       
    String uriString = request.getRequestLine().getUri().substring(13);      

contentType = URLConnection.guessContentTypeFromName(file.getAbsolutePath()); 

                HttpEntity entity = new FileEntity(file, contentType);          
                response.setHeader("Content-Type", contentType);            
    response.setEntity(entity);
}
MobileFileBrowseHandler.java

private BasicHttpProcessor httpproc = null;
private BasicHttpContext httpContext = null;
private HttpService httpService = null;
private HttpRequestHandlerRegistry registry = null;

public WebServer(Context context) {
    this.setContext(context);
    httpproc = new BasicHttpProcessor();
    httpContext = new BasicHttpContext();       
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());
    httpService = new HttpService(httpproc,
        new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());        
    registry = new HttpRequestHandlerRegistry(); 
    registry.register(MOBILE_BASE_PATTERN, new MobileFileBrowseHandler(context));

    httpService.setHandlerResolver(registry);
}

public void runServer() {
    new Thread(new Runnable() {         
        public void run() {
            try {                   
                serverSocket = new ServerSocket(Constants.DEFAULT_SERVER_PORT);     
                serverSocket.setReuseAddress(true);                     
                        while (RUNNING) {                               
                            try {                                   
                                final Socket socket = serverSocket.accept();                                    
                                DefaultHttpServerConnection serverConnection = new DefaultHttpServerConnection();                                                                       
                                serverConnection.bind(socket, new BasicHttpParams());

                                httpService.handleRequest(serverConnection, httpContext); //ERROR UCCURS!!!     
                                serverConnection.shutdown();
                            } catch (IOException e) {
                                e.printStackTrace();
                            } catch (HttpException e) {
                                e.printStackTrace();
                            }
                        }           
                serverSocket.close();                   
            } catch (SocketException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }       
            RUNNING = false;
        }
    }).start();
}
public void handle(HttpRequest request, HttpResponse response,
        HttpContext context) throws HttpException, IOException {
    HttpEntity entity = null;       
    String uriString = request.getRequestLine().getUri().substring(13);      

contentType = URLConnection.guessContentTypeFromName(file.getAbsolutePath()); 

                HttpEntity entity = new FileEntity(file, contentType);          
                response.setHeader("Content-Type", contentType);            
    response.setEntity(entity);
}
我在客户端使用以下代码观看视频或听音乐:

public static void IntentPlayer(Context context, Uri uri, int mode){
    String type;
    switch(mode){
        case 1: type = "video/*"; break;
        case 2: type = "audio/*"; break;            
        default: return;
    }
    Intent intent = new Intent();   
    intent.setAction(android.content.Intent.ACTION_VIEW); 
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);             
    intent.setDataAndType(uri, type);   
    context.startActivity(intent);
}

我做错了什么?任何帮助都将不胜感激

httpcore不支持内容范围,您可以添加它。

您能解决这个问题吗?