zoukankan      html  css  js  c++  java
  • 在谷歌中缓存下载视频离线观看,js代码

     var download=function(urlInfo)
                    {
                        when(createFile(localFileName))
                        .then(function (fileInfo)
                        {
                            var downloaded = function (downloadInfo)
                            {
                                vueThis.cacheStatus = "downloaded";
                                vueThis.downloadProgress = 100;
                                weui.toast("Cache is done");
                                fileInfo.fileWriter.onwriteend = function ()
                                {
                                    var mainPlayer = document.getElementById("mainPlayer");
                                    var prevTime = mainPlayer.currentTime;
                                    mainPlayer.src = fileInfo.fileEntry.toURL();
                                    mainPlayer.currentTime = prevTime;
                                    mainPlayer.play();                       
                                    vueThis.cacheStatus = "playOffline";
                                    vueThis.downloadProgress = 100;
                                    weui.toast("Offline playing");
                                };
                                fileInfo.fileWriter.write(downloadInfo.blob);
                            };
    
                            vueThis.cacheStatus = "downloading";
                            vueThis.cacheMessage = 'Total ' + (urlInfo.size / (1024 * 2014)).toFixed(2) + 'MB';
                            var downloader = Downloader(vueThis.mediaUrl, urlInfo.mimeType, downloadOnProgress);
                            when(downloader).then(downloaded).otherwise(function (e) { console.log(e) });
                        });
                    };
    

      

    function Downloader(url, mimeType, onProgressCallback)
    {
    var deferred = when.defer();
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    //if url is from other domains,
    //Cors settings of that domain is required
    //the settings is as following
    //Access-Control-Allow-Origin *.youzack.com;
    //Access - Control - Allow - Methods GET;
    //Access - Control - Expose - Headers Content - Type, Content - Length;
    xhr.onreadystatechange = function() {
    if (this.readyState == 4) {
    if (this.response != null) {
    var size = parseInt(this.response.byteLength);
    var blob = new Blob([new Uint8Array(this.response)], {type: mimeType});
    var ret = {'size' : size,'blob' : blob};
    deferred.resolve(ret);
    }
    }
    };
    xhr.onprogress = function(e) {
    if(onProgressCallback)
    {
    onProgressCallback(e);
    }
    };
    xhr.responseType = 'arraybuffer';
    xhr.send();
    return deferred.promise;
    };

  • 相关阅读:
    uniapp获取mac地址,ip地址
    uni-app实现扫码
    uniapp常用提示框uni.showToast(OBJECT)
    cookie和session
    JDBC程序执行步骤--repeat
    maven项目中Spring整合Shiro配置文件(示例)
    Could not find action or result: /bos_fore/order_add.action
    datagrid的行编辑
    使用Nexus搭建maven私服二三事
    创建maven-web项目时找不到archetype
  • 原文地址:https://www.cnblogs.com/Tom-yi/p/11738633.html
Copyright © 2011-2022 走看看