Sound url doesn't work with query parameter (there is a work around)

I’m trying to play a sound where the url includes query parameters, but the sound will only play if I remove the query parameter from the url.

The problem is that I’m required to have files hosted on a CDN that I don’t control, which requires certain query parameters to be included in the url. So simply removing the query parameters won’t work in my case.

I created a playground for reproducing the issue, using a sound that doesn’t require authentication. If you comment out line 32, you should hear the sound.
Sound url with query parameter bug | Babylon.js Playground (babylonjs.com)

cc @docEdub

how about this way?
(I fixed it because I posted a wrong solution some time ago. :blush:)

4 Likes

Thank you! That works.

1 Like

You can also set the skipCodecCheck option to true in the Sound constructor. That way you can set the sound to be streamed if you want. The solution posted earlier does not allow the sound to be streamed.

Playground example

let sound = new BABYLON.Sound("sound", soundUrl, null, () => {
    sound.play();
}, {
    skipCodecCheck: true
});
5 Likes


Because of your answer, I know how to works.

so

this mean is not working correct sound?
or does the sound mean that I cannot use the stream function externally?

(https://playground.babylonjs.com/#SVQ864#5)

When you pass a url to the Sound constructor, you can set the streaming option to true to have the sound start playing before it is completely downloaded. This is mainly used for long sound files that you want to start as soon as possible.

The streaming option does nothing if you pass an array buffer to the Sound constructor, because the sound has already been downloaded. So, while the solution posted earlier works fine, it will not work if you want to set the streaming option to true on a long sound file.

1 Like
     sound = new Sound("testSound", arrayBuffer, scene,()=>{
            sound.updateOptions({streaming : true});
            sound!.play();
        });

Can it be solved by updating the options when calling back?
I can’t verify because I can’t check the error.

No, the streaming option only applies when the Sound is constructed.

1 Like

i got it

1 Like

Thank you @docEdub for your solution as well! This will come in handy for streaming music.

1 Like