nanohttpd提供视频,如何使其前后支持视频(使服务器支持http字节范围)

时间:2020-06-24 08:56:04

标签: java android

这是我的代码:

public class VideoServer extends NanoHTTPD {
    public VideoServer() {
        super(8080);
    }

    @Override
    public Response serve(IHTTPSession session) {
        return responseVideoStream(session, "/home/roroco/Dropbox/video/t.mp4");
    }

    public Response responseVideoStream(IHTTPSession session, String videopath) {
        try {
            FileInputStream fis = new FileInputStream(videopath);
            return newChunkedResponse(Response.Status.OK, "video/mp4", fis);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}

视频投放成功,但无法前进和后退

查看我的以下gif文件,当我单击时间进度时,视频无法向后显示

enter image description here

1 个答案:

答案 0 :(得分:0)

我从以下位置找到了解决方案:https://stackoverflow.com/a/23620420/6011193,请参见其#getPartialResponse

这是我的最终代码:

MySql