使用cc.loader.load真机加载微信头像报错

JS代码如下:

       var self = this;
       cc.loader.load(headimgurl, function (err, texture) {
            if (err) {
                cc.log(err);
            }
            self.headimg.spriteFrame = new cc.SpriteFrame(texture);
        });

Creator版本v1.3.3,在Chrome运行,可以加载本地localhost的图片,在手机上加载微信头像报错:
01-06 11:40:57.861 18626-18660/com.youxibi.ddz2 D/CCFileUtils-android.cpp: asset is nullptr
01-06 11:40:57.883 18626-18660/com.youxibi.ddz2 D/cocos2d-x debug info: Error: Download text failed: http://wx.qlogo.cn/mmopen/Po9mkm3Z42tolYpxUVpY6mvCmqalibOpcJ2jG3Qza5qgtibO1NLFNUF7icwCibxPicbGmkoiciaqKEIdvvveIBfEQqal8vkiavHIeqFT/0

期望解决上述问题

2赞

加载微信头像??这个是跨域的问题?

要使用

cc.loader.load({url: headimgurl, type: ‘png’}, …)

因为微信的头像 url 不带后缀名,所以 loader 无法判断类型,需要手动指定,当然了,即便是这样,还是可能无法加载和使用,因为微信头像貌似禁止跨域访问,所以可能需要你从自己的服务器转发

2赞

使用{url: headimgurl, type: ‘png’}之后,浏览器报错:

Uncaught TypeError: Cannot read property ‘queueId’ of undefined
at LoadingItems.append (loading-items.js:440)
at CCLoader.load (CCLoader.js:213)
at scene2.onLoad (scene2.js:19)
at scene2.__onNodeActivated (CCComponent.js:697)
at cc_Node._activeRecursively (CCNode.js:955)
at cc_Node._onActivatedInHierarchy (CCNode.js:1023)
at cc_Scene._activate (CCScene.js:124)
at _Class.runSceneImmediate (CCDirector.js:602)
at CCDirector.js:839
at CCLoader. (CCAssetLibrary.js:104)
append @ loading-items.js:440
load @ CCLoader.js:213
onLoad @ scene2.js:19
__onNodeActivated @ CCComponent.js:697
_activeRecursively @ CCNode.js:955
_onActivatedInHierarchy @ CCNode.js:1023
_activate @ CCScene.js:124
runSceneImmediate @ CCDirector.js:602
(anonymous) @ CCDirector.js:839
(anonymous) @ CCAssetLibrary.js:104
(anonymous) @ CCLoader.js:195
(anonymous) @ utils.js:55

你好 你的问题解决了吗?

你的问题解决了吗?

加后缀.jpg

请问这个问题现在是什么情况?

这个问题,我解决了。。思想是吧 微信的图片,拷贝到自己的服务器,然后服务器设置跨域 为 Access-Control-Allow-Origin 为 *就行了。。但是panda 大神,,我有另外个问题,,我对IOS完全不懂,android也不懂,JAVA到时可以,那么我想做一个游戏里面的录音功能,,怎么做呢??我看一篇帖子说有教程,能否给我一下呢?谢谢。

1赞

之前有一个很简单的 demo,是基于 iOS API 做的,项目仓库在这里

https://github.com/pandamicro/ReflectionSample

具体的 iOS 录音实现在这里

https://github.com/pandamicro/ReflectionSample/blob/master/build/jsb-link/frameworks/runtime-src/Classes/AudioRecorder.h

1赞

谢熊猫大大挂念,目前用了一个取巧的办法,给微信的图片链接加后缀“.jpg”就可以下载了,例如:http://wx.qlogo.cn/mmopen/Po9mkm3Z42tolYpxUVpY6mvCmqalibOpcJ2jG3Qza5qgtibO1NLFNUF7icwCibxPicbGmkoiciaqKEIdvvveIBfEQqal8vkiavHIeqFT/0.jpg

1赞

你好 按照你的方法 没有成功呀,是哪里有错吗?
var self = this;
var headimgurl =‘http://wx.qlogo.cn/mmopen/Po9mkm3Z42tolYpxUVpY6mvCmqalibOpcJ2jG3Qza5qgtibO1NLFNUF7icwCibxPicbGmkoiciaqKEIdvvveIBfEQqal8vkiavHIeqFT/0.jpg
cc.loader.load(headimgurl, {type: ‘jpg’}, function (err, texture) {
if (err) {
cc.log(err);
}
self.headimg.spriteFrame = new cc.SpriteFrame(texture);
});

cc.loader.load(headimgurl, function (err, texture) {

});

这种方法对于微信来说还可以,但是扣扣图片就不行了

我之前用的加‘.jpg’后缀 解决了这个问题 但是现在又不灵了 请问@萧何 遇到没有

向各位请教一下,这种方式加载的图片,需要手动释放吗?如果需要的话应该怎么释放?

使用下面代码可以解决我的问题.
cc.loader.load({url:url,type:‘jpg’}, function(err, texture){
})
其中type为jpg和png都能正常运行

加上图片的类型type字段就可以了,嘿嘿✧(≖ ◡ ≖✿)嘿嘿 送你一朵小花:hibiscus:

这个方法正确,:+1:

加.jpg 真机 微信图片 有时候 还时显示 不出来啊
panda说的 转发 有人 试过了吗 可以 用吗
期待回答