danikula / danikula/AndroidVideoCache

Three Basic Qqestions Need Author's Kind Help

未关闭
#191 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Java
星标
5.5k
派生
1.2k
PR 合并指标
30 天内没有已合并 PR

描述

Hi, Dear Alexey Danilov:
Quite perfect and useful lib for Android, thanks for sharing your efforts to make us conveniently coding.
There are three uncertainty from my side, it will be greate honor for me if I can get kindly help from you.

### When I want to learn this lib in detail, a mimesis was done. My purpose was to provide a mp4 file to a VideoView as a server.
#### First I start a ServerSocket:
ServerSocketFactory factory = ServerSocketFactory.getDefault();
InetAddress address = InetAddress.getByName("127.0.0.1");
serverSocket = factory.createServerSocket(30001, 9, address);
#### When the request from VideoView arrives:

while (!Thread.currentThread().isInterrupted()) {

Socket socket = serverSocket.accept();
InputStream inputStream = socket.getInputStream();
String read = Utils.read(inputStream);

// The same as your lib, make a OK reponse.
GetRequest request = new GetRequest(read);
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream());
String responseHeaders = newResponseHeaders(request);
out.write(responseHeaders.getBytes("UTF-8"));

//read a mp4 file from storage
byte[] buffer = new byte[1024 * 512];
int readBytes;
int offset = 0;
while ((readBytes = read(buffer, offset, buffer.length)) != -1) {
out.write(buffer, 0, readBytes);
offset += readBytes;
}

out.flush();
}

#### The VideoView works well, but when I change the buffer size asbyte[] buffer = new byte[8192], the VideoView can not play ! I changed the BufferedOutputStream as OutputStream and I tried flush the stream, it still can not work, only I make the buffer size biger than 8192, it will work, Could you please help me to find this reason ?

### My second question based on the first one. when I use this lib, I saw two times request from VideoView in different threads when the source has alredy been cached, the logs as below:

#### This is the first request info form VideoView for the first time:
GET /http%3A%2F%2F192.168.27.9%3A8000%2Fadv.mp4 HTTP/1.1
Accept: */*
Range: bytes=0-
Connection: close
Host: 127.0.0.1:44663
User-Agent: Mozilla/4.0 (compatible; MS IE 6.0; (ziva))
#### We replaied like this :
HttpProxyCache.processRequest: HTTP/1.1 206 PARTIAL CONTENT
Accept-Ranges: bytes
Content-Length: 286255909
Content-Range: bytes 0-286255908/286255909
Content-Type: video/mp4
#### The second request arrives with offset:
/http%3A%2F%2F192.168.27.9%3A8000%2Fadv.mp4 HTTP/1.1
Accept: */*
Range: bytes=517067-
Connection: close
Host: 127.0.0.1:44663
User-Agent: Mozilla/4.0 (compatible; MS IE 6.0; (ziva))
#### And we replaied like this
HttpProxyCache.processRequest: HTTP/1.1 206 PARTIAL CONTENT
Accept-Ranges: bytes
Content-Length: 285738842
Content-Range: bytes 517067-286255908/286255909
Content-Type: video/mp4

#### Though the lib works well, I am still curious about why I can only see on time request from VidewView from my pervious question but see two times from your lib ? It takes me a long time to find the answer and still I did not , could you please help me to know the answer ?

### My last question is I saw when building HttpProxyCacheServer, we freeze thread, wait for server starts, is this necessary to freeze the main thread ?

Thanks again!

贡献指南

这个仓库没有索引到贡献指南

调研方向

首先阅读 HttpProxyCacheServer 的启动路径和 HttpProxyCache.processRequest,然后将它们与提供的 ServerSocket 和 VideoView 流程进行比较。该 issue 要求解释缓冲区大小的行为、重复的 range 请求以及启动线程等待的问题;当三个问题都有清晰且有文档记录的回答时,即可视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, java
领域
mobile-dev, networking
Issue 类型
文档
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
15/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。