How to add sounds using JQM and IntelXDK

I am working on an application and use IntelXDK to create it. I need to play some sounds if the conditions are met, at first I tried HTML5 with JS and on the desktop, but when building it has no sound ...

First try - HTML5 and JS

<audio src="snd/yes.mp3" id="yes"></audio>
<audio src="snd/no.mp3" id="no"></audio>

if(condition) {
    $('#yes').trigger("play");
} else {
    $('#no').trigger("play");
}

Then I tried the built-in version of IntelXDK, which looks like this:

if(condition) {
    intel.xdk.player.playSound("snd/yes.mp3");
} else {
    intel.xdk.player.playSound("snd/no.mp3");
}

Not only does it not work, but also the rest of my code does not allow a popup and page change to be triggered.

Does anyone know how to fix this? Do I need to preload sounds before playing them?

** UPDATE

, HTML5 Audio, , , snd, ... ?

+4
1

, "" , , "snd" . , , , , , XDK, , . , , .

// getWebPath() returns the location of index.html
// getWebRoot() returns URI pointing to index.html

function getWebPath() {
    "use strict" ;
    var path = window.location.pathname ;
    path = path.substring( 0, path.lastIndexOf('/') ) ;
    return 'file://' + path ;
}

function getWebRoot() {
    "use strict" ;
    var path = window.location.href ;
    path = path.substring( 0, path.lastIndexOf('/') ) ;
    return path ;
}
+1

All Articles