Tom-yi
 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;
};

分类:

技术点:

相关文章:

  • 2021-12-15
  • 2021-12-12
  • 2021-11-14
  • 2022-12-23
  • 2022-01-19
猜你喜欢
  • 2021-10-06
  • 2021-05-31
  • 2021-10-31
  • 2021-12-01
  • 2021-09-08
  • 2022-01-14
  • 2021-12-27
相关资源
相似解决方案