var url = item.url;
console.log(“gif:GIF Download Handler准备开始下载…” + url)
// var xhr = cc.loader.getXMLHttpRequest();
let xhr = new XMLHttpRequest();
xhr.responseType = "arraybuffer";
xhr.onreadystatechange = function () {
console.log("gif:xhr.readyState:" + xhr.readyState)
console.log("gif:xhr.status:" + xhr.status)
if (xhr.readyState === 4 && xhr.status === 200) {
console.log("gif:xhr下载成功")
var arrayBuffer = xhr.response;
if (arrayBuffer) {
var result = new Uint8Array(arrayBuffer);
let gif = new GIF();
console.log("gif:GIFDownLoader GIF下载完成,开始解析...")
gif.handle(result, MGOBEManager.getInstance().getUIMgr(), cb)
}
else {
cb("no response", null);
}
}
}
xhr.timeout = 5000;
xhr.onload = function (oEvent) {
// cc.log("onloaod111111111:",JSON.stringify(oEvent))
// var arrayBuffer = xhr.response;
// if (arrayBuffer) {
// var result = new Uint8Array(arrayBuffer);
// let gif = new GIF();
// console.log("gif:GIFDownLoader GIF下载完成,开始解析...")
// gif.handle(result, MGOBEManager.getInstance().getUIMgr(), cb)
// }
// else {
// cb("no response", null);
// }
}
xhr.onabort = function (oEvent) {
console.log("onabort" + oEvent)
}
xhr.onerror = function (oEvent) {
console.log("onerror" + oEvent)
}
xhr.onloadend = function (oEvent) {
console.log("onloadend" + oEvent)
}
xhr.onloadstart = function (oEvent) {
console.log("onloadstart" + oEvent)
}
xhr.onprogress = function (oEvent) {
console.log("onprogress" + oEvent)
}
xhr.ontimeout = function (oEvent) {
console.log("ontimeout" + oEvent)
}
// 错误处理
xhr.onerror = function (arg0) {
cc.error("下载gif错误:", arg0)
}
try {
xhr.open("GET", url, true);
} catch (error) {
console.log("xhropen失败!!!")
console.log(error)
}
console.log("gif:send..." + url)
xhr.send();
基本上就是这样了,在Andrdoid上运行,不进onload,也不调onreadystatechange(仅在开始的时候调用一次,状态为0-开始,后面就再也没有反应了)
希望大家贡献一些思路,解决这个问题。