danikula / danikula/AndroidVideoCache

Three Basic Qqestions Need Author's Kind Help

Đang mở
#191 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Java
Star
5.5k
Fork
1.2k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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!

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Start by reading the HttpProxyCacheServer startup path and HttpProxyCache.processRequest, then compare them with the provided ServerSocket and VideoView flow. The issue asks for explanations of buffer-size behavior, repeated range requests, and startup thread waiting; done would be a clear documented answer to all three questions.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
android, java
Lĩnh vực
mobile-dev, networking
Loại issue
Tài liệu
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
15/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.