locked
Sound effect in gameplay

    Question

  • Hi Guys,

    I am creating a small game for windows 8.1 with Javascript and HTML5. I am having a small problem, on click I would like to play a sound, here is the code which I have written.

    var sfx_click = new Audio("/Sfx/jump.ogg");
            sfx_click.volume = 1;
            sfx_click.play();

    The above piece of code is not playing the sound. I even tried Sound.js,

    createjs.Sound.play("/Sfx/21Guns.mp3", createjs.Sound.INTERUPT_ANY);

    Which did not work. I would like to know what I might be missing here.

    Should I enable anything in appmanifest??

    Any suggestion is really appreciated.

    Regards,

    Rakesh

    Saturday, August 09, 2014 1:54 PM

Answers

  • Hi Rakesh,

    You don't need enable any thing in appmanifest if your audio file exists in the project.

    To play the sound in WinJS, you may need a <audio> tag with the source, your first code seems correct as the HTML below:

    <audio>
        <source src="uri" type="audioType" />
    </audio>
    

    I don't know if some third-party code can work together with Windows Store App, you may need ask owner of Sound.js to see how they can work together with WinJS.

    IMPORTANT: I don't think you can play the ogg format with Windows Store App, see Supported audio and video formats

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, August 11, 2014 1:33 AM
    Moderator