Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soundSprite Not Properly Loading In #331

Open
WindowsTV opened this issue Feb 1, 2023 · 1 comment
Open

soundSprite Not Properly Loading In #331

WindowsTV opened this issue Feb 1, 2023 · 1 comment

Comments

@WindowsTV
Copy link

I am trying to load in an audioSprite as a JSON in the current version of createjs/soundjs. I am not sure if this is supported but let explain what happens.

var assetsPath = "./AUDIO/";
var audio = [
	{src: "CASSIDY/CASSIDY.json" + _localCache.getExtraCacheVersion(), data:{type:"tlk"}},
];   

createjs.Sound.registerPlugins([createjs.WebAudioPlugin]);
createjs.Sound.alternateExtensions = ["wav", "mp3"];
createjs.Sound.addEventListener("fileload", createjs.proxy(soundLoaded, this));
createjs.Sound.registerSounds(audio, assetsPath);			
	

Using the code above loads in the WAV audio file and appears to actually apply the id to the file but when I go to play the audio it says the audio was never loaded in and tried to load it again at the wrong directory.

A quick fix would be load the JSON in on another loadQue then pushing it into the sound que.

@WindowsTV
Copy link
Author

WindowsTV commented Feb 1, 2023

This is my temporary fix, overridden some functions and added a new:

createjs.Sound.registerSounds = function (sounds, basePath) {
	console.log("AUDIO HI");
	var returnValues = [];
	if (sounds.path) {
		if (!basePath) {
			basePath = sounds.path;
		} else {
			basePath = basePath + sounds.path;
		}
		sounds = sounds.manifest;
		// TODO document this feature
	}
	for (var i = 0, l = sounds.length; i < l; i++) {
		if(sounds[i].data.isAudioSprite === true){
			console.log(sounds[i]);
			var _idFromSrc = sounds[i].src.split("/");			
			var _loadItem = {id:(_idFromSrc[1].split(".")[0] + "-JSON"), type:"json", src:(basePath + sounds[i].src)};
			var _queue = new createjs.LoadQueue();
			_queue.on("complete", createjs.Sound.parseLoadedAudioSprite, null, true, {loadQue: _queue, id: _loadItem.id, src: (basePath + sounds[i].src)});
			_queue.loadFile(_loadItem);								
		}else returnValues[i] = createjs.Sound.registerSound(sounds[i].src, sounds[i].id, sounds[i].data, basePath, sounds[i].defaultPlayProps);
	}
	console.log(returnValues);
	return returnValues;
};
createjs.Sound.parseLoadedAudioSprite = function (e, payload) {
	let _json = payload.loadQue.getResult(payload.id);
	let _temp = {
		src:payload.src, 
		data: _json.data
	};
	createjs.Sound.registerSound(_temp.src, payload.id.split("-")[0], _temp.data, null, null);
};

I don't think it's a good one because it could break people's loading schemes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant