none
Problem with playing sound in games that are written in javascript HTML5 (Windows Phone)

    Question

  • Prompt decision to play on HTML5 and javascript  (Windows Phone). Need help in the implementation of sound and effects. Which is better to use the library. At the moment I do not play multiple sounds simultaneously, each following the sound stops coming.
    Monday, January 13, 2014 3:28 PM

Answers

  • I see... I think the problem here is that, on Windows Phone, the media pipeline only decodes one complex audio stream at a time.

      To play multiple sounds at once an app can use the XNA SoundEffect Class which mixes PCM audio (*.wav files) into the audio down stream from the decoder.  To use the SoundEffect class in your HTML5 app your script would need to signal the host application framework using window.external.notify and in the host code you would need to handle the ScriptNotify event of the WebBrowser control.


    -Eric.

    • Marked as answer by DenBraun Wednesday, January 15, 2014 6:23 AM
    Tuesday, January 14, 2014 11:40 PM

All replies

  • What method are you currently using to play sounds?

    Which library are you asking about?


    -Eric.

    Tuesday, January 14, 2014 2:34 PM
  • function loadSound(){
        var arrSound = [
            'audio/game-sound.mp3',
            'audio/dead.mp3',
            'audio/kick-tree.mp3',
            'audio/kick-wall.mp3',
            'audio/kick-kol.mp3',
            'audio/pull-player.mp3'
        ];
        var statusAudioCategory = "GameMedia";
        for(var i=0; i<arrSound.length; i++){
            if(i === 1) statusAudioCategory = "GameEffects";
            var audtag = document.createElement('audio');
            audtag.setAttribute("id", "audtag"+i);
            audtag.setAttribute("msAudioCategory", statusAudioCategory);
            audtag.setAttribute("src", arrSound[i]);
            document.getElementById("MediaElement").appendChild(audtag);
            audtag.load();
            if(i === 0) audtag.play();
        }    
    }
    function soundPlay(id){
        document.getElementById("audtag"+id).play();
    }
    For example a very simple example. In all browsers work fine, as all applications running in windows 8, but on the WP sounds interrupt one another.
    Tuesday, January 14, 2014 10:53 PM
  • I see... I think the problem here is that, on Windows Phone, the media pipeline only decodes one complex audio stream at a time.

      To play multiple sounds at once an app can use the XNA SoundEffect Class which mixes PCM audio (*.wav files) into the audio down stream from the decoder.  To use the SoundEffect class in your HTML5 app your script would need to signal the host application framework using window.external.notify and in the host code you would need to handle the ScriptNotify event of the WebBrowser control.


    -Eric.

    • Marked as answer by DenBraun Wednesday, January 15, 2014 6:23 AM
    Tuesday, January 14, 2014 11:40 PM
  • Yes, thank you, I have also come to this conclusion, tried everything.
    Wednesday, January 15, 2014 6:23 AM