Problem to trying playing a sound locally on my computer

Hi to everybody, i want to simply play a sound or music with babylon js, to play the sounds resources of my computer…Nothing works here…can somebody help me please??
i put the index file in a folder and in another subfolder called sounds i put the file test.wav or test.mp3…but for now i use test.wav .
Ok… i thinked that my sound point to this folder ok .: sounds/test.wav
but nothing works here…can somebody help me please??
here below i put the code…

here my code:

    <title>Babylon.js sample code</title>

    <!-- Babylon.js -->
    <script src="https://code.jquery.com/pep/0.4.2/pep.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.2/dat.gui.min.js"></script>
    <script src="https://preview.babylonjs.com/ammo.js"></script>
    <script src="https://preview.babylonjs.com/cannon.js"></script>
    <script src="https://preview.babylonjs.com/Oimo.js"></script>
    <script src="https://preview.babylonjs.com/earcut.min.js"></script>
    <script src="https://preview.babylonjs.com/babylon.js"></script>
    <script src="https://preview.babylonjs.com/inspector/babylon.inspector.bundle.js"></script>
    <script src="https://preview.babylonjs.com/materialsLibrary/babylonjs.materials.min.js"></script>
    <script src="https://preview.babylonjs.com/proceduralTexturesLibrary/babylonjs.proceduralTextures.min.js"></script>
    <script src="https://preview.babylonjs.com/postProcessesLibrary/babylonjs.postProcess.min.js"></script>
    <script src="https://preview.babylonjs.com/loaders/babylonjs.loaders.js"></script>
    <script src="https://preview.babylonjs.com/serializers/babylonjs.serializers.min.js"></script>
    <script src="https://preview.babylonjs.com/gui/babylon.gui.min.js"></script>

    <style>
        html, body {
            overflow: hidden;
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }

        #renderCanvas {
            width: 100%;
            height: 100%;
            touch-action: none;
        }
    </style>
</head>
var canvas = document.getElementById("renderCanvas");
    var engine = null;
    var scene = null;
    var sceneToRender = null;
    var createDefaultEngine = function() { return new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true }); };
    // You have to create a function called createScene. This function must return a BABYLON.Scene object

// You can reference the following variables: engine, canvas
// You must at least define a camera

var createScene = function() {
var scene = new BABYLON.Scene(engine);

//var camera = new BABYLON.ArcRotateCamera("Camera", -Math.PI / 2, Math.PI / 2, 12, BABYLON.Vector3.Zero(), scene);
var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
camera.attachControl(canvas, true);

return scene;

};

var gunshot = new BABYLON.Sound(“gunshot”, “sounds/test.wav”, scene);

window.addEventListener(“mousedown”, function(evt) {
// left click to fire
if (evt.button === 0) {
gunshot.play();
}
});
var engine;
try {
engine = createDefaultEngine();
} catch(e) {
console.log(“the available createEngine function failed. Creating the default engine instead”);
engine = createDefaultEngine();
}
if (!engine) throw ‘engine should not be null.’;
scene = createScene();;
sceneToRender = scene

    engine.runRenderLoop(function () {
        if (sceneToRender) {
            sceneToRender.render();
        }
    });

    // Resize
    window.addEventListener("resize", function () {
        engine.resize();
    });
</script>

What browser are you using ? There are issues with Chrome - you have to use a button click.

Stay Safe All, gryff :slight_smile:

Dear gryff, thanks a lot for your support…but i use window10 8gbram 120gb ssd computer hp amd-e2-3200 apu with radeonhd graphics 2.40ghz x64 core…
I see this problem with any browser for win10… there’s few examples to work with sounds.with babylonjs…thanks .lestroso…

@FaSaSoftware : Can you post a playground with an example ? And do you get any sound with this example:

Train

Hit the “c” key, then click on the red signal. Should work fine in Firefox, a button may appear in top left corner of Chrome - just click it.

Stay Safe, gryff :slight_smile:

Dear gryff, i enclose here the code you need for my problem…i cant load and play a sound in any web…but perhaphs is my fault… the demo you gave me was fine…but also the demo on babylonjs works… but if i try to customize my sounds…i don’t hear nothing!!..thank a lot again for the help… bye lestroso…

here the link of my zip done with playground: https://easyupload.io/ddae2s

Here nothing works… i’m trying to work with babylonjs…but i have installed nothing on my computer…something works…the graphic examples…but the audio don’t…works…what do i have to install? wittch step do i have to make??? thank a lot lestroso

Hi. You run program with local server? Or simply open html in browser? If you run program without local server on local machine you get CORS blocked resources. You cant use crossdomain resources! And second thing browser cant start audio without user interaction so you need play sound on click in first time. Open console and show us screenshot after starting your program

1 Like

@kvasss : Exactly. Never played when I tried to load “file …”

When I tried with my local server (EasyPHP) it worked with either the “babylon.inspector.bundle.js” removed as @Necips suggested, or, with the inspector.bundle script still there, it gave me this error (image below) - but it did work!

Stay Safe All, gryff :slight_smile:

error01

Dear kvasss, i’m sorry i’m newbe…in truth i only used my web browswer only…firefox80.0.1… i don’t know how to use a local server…i have tryed to look around… but i don’t see any real step by step tutorial to start from the beginning…do you know any??? best regards lestroso

Sorry but there no easy way. and you cant work without basic js knowlege.
Try this as start point ES6 - Babylon.js Documentation

and only one easy way is IDE with local server plugin like vscode LiveServer
https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer
run server and open in browser something like 127.0.0.1:3500 your index.html

Thanks again kvasss… i’ll try your link… i 'll try to dive in the document explanation… thanks again…lestroso