Playing sound by script

Can anyone can explain me why this did't work?


AudioManager.playSe(Cancel1.ogg, 90, 100, 0);


It's alway told me Cancel1 was not defined. Thanks.
I've moved this thread to Javascript Support. Please be sure to post your threads in the correct forum next time. Thank you.
There are 2 possible explanations.  Either:


A:  You're using the wrong file ext.  It may be that you need .m4a, not .ogg.


B:  The extension isn't necessary for the filename.


I'm leaning towards B, but try both and see if either of those work.
Two things, actually--


1. the extension isn't necessary for the filename


2. the format needs to be as an "object". Basically, it needs these things around it: { }


So:

Code:
AudioManager.playSe({name: "filename", pan: 0, pitch: 100, volume: 100});
AudioManager.playSe({name: "Cancel1", pan: 90, pitch: 100, volume: 0});  giv objet error


AudioManager.playSe({"Cancel1", 90, 100, 0});    give unexpected token ,


I miss something?
I took a closer look at the playSe code in the file, and it only uses the filename as an argument.  Adding the other numbers may be the issue.  Try this:


AudioManager.playSe('Cancel1');
@shockra No, it takes an object, not a filename.


You see that it references things like se.name, which are variables within an object, so se cannot be simply a filename.


AudioManager.playSe = function(se) {
if (se.name) {
this._seBuffers = this._seBuffers.filter(function(audio) {
return audio.isPlaying();
});
var buffer = this.createBuffer('se', se.name);
this.updateSeParameters(buffer, se);
buffer.play(false);
this._seBuffers.push(buffer);
}
};


@XGuarden I found it-- the problem here is the double quotes. Script commands execute using eval and because of this have problems when there are quotation marks identical to what javascript uses by default (it breaks the eval string) so you need to use single quotes:

Code:
AudioManager.playSe({name: 'filename', pan: 0, pitch: 100, volume: 100});
Working now. But I realize that player are able to move while the soind playing, any wait to restrict movement?

Original thread: https://forums.rpgmakerweb.com/threads/playing-sound-by-script.73752/