mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
@@ -540,11 +540,12 @@ JS.mixin(cc.Audio.prototype, {
|
||||
}else if(!SWA && i > this._maxAudioInstance){
|
||||
cc.log("Error: %s greater than %d", url, this._maxAudioInstance);
|
||||
}else{
|
||||
audio = cc.loader.getRes(url);
|
||||
var item = cc.loader.getItem(url);
|
||||
audio = item && item.audio ? item.audio : null;
|
||||
if(!audio){
|
||||
cc.loader.load(url);
|
||||
var item = cc.loader.getItems().map[url];
|
||||
audio = item ? item.content : null;
|
||||
item = cc.loader.getItem(url);
|
||||
audio = item && item.audio ? item.audio : null;
|
||||
if (!audio) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -109,10 +109,13 @@ JS.mixin(cc.loader, {
|
||||
* cc.loader.load('a.png', function (err, tex) {
|
||||
* cc.log('Result should be a texture: ' + (tex instanceof cc.Texture2D));
|
||||
* });
|
||||
*
|
||||
* // load a.png from resources folder with no extension.
|
||||
* cc.loader.load('resources://a', function (err, tex) {
|
||||
* cc.log('Result should be a texture: ' + (tex instanceof cc.Texture2D));
|
||||
*
|
||||
* cc.loader.load('http://example.com/a.png', function (err, tex) {
|
||||
* cc.log('Should load a texture from external url: ' + (tex instanceof cc.Texture2D));
|
||||
* });
|
||||
*
|
||||
* cc.loader.load({id: 'http://example.com/getImageREST?file=a.png', type: 'png'}, function (err, tex) {
|
||||
* cc.log('Should load a texture from RESTful API by specify the type: ' + (tex instanceof cc.Texture2D));
|
||||
* });
|
||||
*
|
||||
* cc.loader.load(['a.png', 'b.json'], function (errors, results) {
|
||||
|
||||
@@ -57,7 +57,7 @@ function loadAudioFromExtList (url, typeList, audio, cb){
|
||||
context['decodeAudioData'](request.response, function (buffer) {
|
||||
//success
|
||||
audio.setBuffer(buffer);
|
||||
cb(null, audio);
|
||||
cb(null, audio.src);
|
||||
}, function() {
|
||||
//error
|
||||
loadAudioFromExtList(url, typeList, audio, cb);
|
||||
@@ -81,7 +81,7 @@ function loadAudioFromExtList (url, typeList, audio, cb){
|
||||
termination = true;
|
||||
element.pause();
|
||||
document.body.removeChild(element);
|
||||
cb('Audio load timeout : ' + url, audio);
|
||||
cb('Audio load timeout : ' + url, null);
|
||||
}
|
||||
}, 8000);
|
||||
|
||||
@@ -97,7 +97,7 @@ function loadAudioFromExtList (url, typeList, audio, cb){
|
||||
element.removeEventListener('canplaythrough', success, false);
|
||||
element.removeEventListener('error', failure, false);
|
||||
element.removeEventListener('emptied', emptied, false);
|
||||
!termination && cb(null, audio);
|
||||
!termination && cb(null, url);
|
||||
cbCheck = true;
|
||||
clearTimeout(timer);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ function loadAudioFromExtList (url, typeList, audio, cb){
|
||||
var emptied = function(){
|
||||
termination = true;
|
||||
success();
|
||||
cb(null, audio);
|
||||
cb(null, url);
|
||||
};
|
||||
|
||||
element.addEventListener('canplaythrough', success, false);
|
||||
@@ -170,7 +170,8 @@ function downloadAudio (item, callback) {
|
||||
}
|
||||
|
||||
// hack for audio to be found before loaded
|
||||
item.content = audio;
|
||||
item.content = url;
|
||||
item.audio = audio;
|
||||
loadAudioFromExtList(url, typeList, audio, callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -445,6 +445,15 @@ JS.mixin(Pipeline.prototype, {
|
||||
return this._items;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns an item in pipeline.
|
||||
* @method getItems
|
||||
* @return {LoadingItems}
|
||||
*/
|
||||
getItem: function (url) {
|
||||
return this._items.map[url];
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes an item in pipeline, no matter it's in progress or completed.
|
||||
* @method removeItem
|
||||
|
||||
+9
-5
@@ -49,6 +49,10 @@ function downloadText (item, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
function downloadAudio (item, callback) {
|
||||
callback(null, item.url);
|
||||
}
|
||||
|
||||
cc.loader.addDownloadHandlers({
|
||||
// JS
|
||||
'js' : downloadScript,
|
||||
@@ -66,11 +70,11 @@ cc.loader.addDownloadHandlers({
|
||||
'image' : empty,
|
||||
|
||||
// Audio
|
||||
'mp3' : empty,
|
||||
'ogg' : empty,
|
||||
'wav' : empty,
|
||||
'mp4' : empty,
|
||||
'm4a' : empty,
|
||||
'mp3' : downloadAudio,
|
||||
'ogg' : downloadAudio,
|
||||
'wav' : downloadAudio,
|
||||
'mp4' : downloadAudio,
|
||||
'm4a' : downloadAudio,
|
||||
|
||||
// Txt
|
||||
'txt' : downloadText,
|
||||
|
||||
Reference in New Issue
Block a user