Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play cached video offline #13

Closed
ongakuer opened this issue Sep 18, 2015 · 2 comments
Closed

Play cached video offline #13

ongakuer opened this issue Sep 18, 2015 · 2 comments
Labels

Comments

@ongakuer
Copy link

I can not play cached video offline.

From this code:

private String newResponseHeaders(GetRequest request) throws IOException, ProxyCacheException {
        String mime = source.getMime();
        boolean mimeKnown = !TextUtils.isEmpty(mime);
        int length = cache.isCompleted() ? cache.available() : source.available();
        boolean lengthKnown = length >= 0;
        long contentLength = request.partial ? length - request.rangeOffset : length;
        boolean addRange = lengthKnown && request.partial;
        return new StringBuilder()
                .append(request.partial ? "HTTP/1.1 206 PARTIAL CONTENT\n" : "HTTP/1.1 200 OK\n")
                .append("Accept-Ranges: bytes\n")
                .append(lengthKnown ? String.format("Content-Length: %d\n", contentLength) : "")
                .append(addRange ? String.format("Content-Range: bytes %d-%d/%d\n", request.rangeOffset, length, length) : "")
                .append(mimeKnown ? String.format("Content-Type: %s\n", mime) : "")
                .append("\n") // headers end
                .toString();
    }

HttpProxyCache will always get mime from Internet, and throw Exception if no network.
Changed like this can work well:

private String newResponseHeaders(GetRequest request) throws IOException, ProxyCacheException {
        int length;
        String mime = null;
        if (cache.isCompleted()) {
            length = cache.available();
        } else {
            length = source.available();
            mime = source.getMime();
        }
        boolean mimeKnown = !TextUtils.isEmpty(mime);
        boolean lengthKnown = length >= 0;
        long contentLength = request.partial ? length - request.rangeOffset : length;
        boolean addRange = lengthKnown && request.partial;
        return new StringBuilder().append(
                request.partial ? "HTTP/1.1 206 PARTIAL CONTENT\n" : "HTTP/1.1 200 OK\n")
                .append("Accept-Ranges: bytes\n")
                .append(lengthKnown ? String.format("Content-Length: %d\n", contentLength) : "")
                .append(addRange ? String.format("Content-Range: bytes %d-%d/%d\n",
                        request.rangeOffset, length, length) : "")
                .append(mimeKnown ? String.format("Content-Type: %s\n", mime) : "").append(
                        "\n") // headers end
                .toString();
    }
@danikula
Copy link
Owner

Fixed in 2.1.2

@danikula
Copy link
Owner

@ongakuer thanks for reporting about problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants