seadroid icon indicating copy to clipboard operation
seadroid copied to clipboard

support play streaming video instead of after download it to play.

Open max32002 opened this issue 8 years ago • 0 comments

In Utils.java

    public static boolean isViewableVideo(String name) {
        String suffix = name.substring(name.lastIndexOf(46) + 1).toLowerCase();
        if (suffix.length() == 0) {
            return false;
        }
        if (suffix.equals("mkv") || suffix.equals("vob") || suffix.equals("rm") || suffix.equals("rmvb") || suffix.equals("ra") || suffix.equals("mov") || suffix.equals("mp4") || suffix.equals("avi") || suffix.equals("3pg") || suffix.equals("m4v") || suffix.equals("m4a") || suffix.equals("flv") || suffix.equals("flac") || suffix.equals("ts") || suffix.equals("m2ts") || suffix.equals("wmv") || suffix.equals("aac")) {
            return true;
        }
        String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(suffix);
        if (mime != null) {
            return mime.contains("video");
        }
        return false;
    }

in BrowserActivity:

    @Override
    public void onFileSelected(SeafDirent dirent) {
        final String fileName= dirent.name;
        final long fileSize = dirent.size;
        final String repoName = navContext.getRepoName();
        final String repoID = navContext.getRepoID();
        final String dirPath = navContext.getDirPath();
        final String filePath = Utils.pathJoin(navContext.getDirPath(), fileName);
        final SeafRepo repo = dataManager.getCachedRepoByID(repoID);

        // Encrypted repo doesn\`t support gallery,
        // because pic thumbnail under encrypted repo was not supported at the server side
        if (Utils.isViewableImage(fileName)
                && repo != null && !repo.encrypted) {
            WidgetUtils.startGalleryActivity(this, repoName, repoID, dirPath, fileName, account);
            return;
        }

        final File localFile = dataManager.getLocalCachedFile(repoName, repoID, filePath, dirent.id);
        if (localFile != null) {
            WidgetUtils.showFile(this, localFile);
            return;
        }
        else {
            if (Utils.isViewableVideo(fileName)
                    && repo != null && !repo.encrypted) {
                new StreamingTask().execute(repoID, filePath);
                return;
            }
        }
        startFileActivity(repoName, repoID, filePath, fileSize);
    }

On server side, add new API to get temporary link: https://www.dropbox.com/developers/documentation/http/documentation#files-get_temporary_link

# As per RFC 2616 14.16, if an invalid Range header is specified,
# the request will be treated as if the header didn't exist.

# As per RFC 2616 14.35.1, a range is not satisfiable only: if
# the first requested byte is equal to or greater than the
# content, or when a suffix with length 0 is specified

# Note: only return HTTP 206 if less than the entire range has been
# requested. Not only is this semantically correct, but Chrome
# refuses to play audio if it gets an HTTP 206 in response to
# ``Range: bytes=0-``.

max32002 avatar Mar 29 '17 04:03 max32002