samedi 3 janvier 2015

Cordova - Control several sounds on Android

I manage to play several sounds on Android (Cordova 4.1) but now I would like to dynamically change the volume of each video.


My code for playing sounds is the following:



function onDeviceReady() {
document.querySelector("#play").addEventListener("touchend", playMP3(), false);

function playMP3() {
var mp3_1 = getMediaURL("audio/sound1.mp3");
var mp3_2 = getMediaURL("audio/sound2.mp3");
media1 = new Media(mp3_1, null, mediaError);
media2 = new Media(mp3_2, null, mediaError);
media1.play();
media2.play();
}

function getMediaURL(s) {
if(device.platform.toLowerCase() === "android") return "/android_asset/www/" + s;
return s;
}
function mediaError(e) {
alert('Media Error');
alert(JSON.stringify(e));
}
}


Then I would like to control volume with something like media1.volume = 0.5; from outside the onDeviceReady function but I can't make it work...


Any idea of what I'm missing?


Aucun commentaire:

Enregistrer un commentaire