I am trying to play an audio file turning a page using turn.js; it is not a flip sound, it is the audio of the text printed in that couple of pages or a music if on the pages there is the text of a song. Seems that I am able to play it but I am not able to stop the sound if the user turns the page prematurely. In that case I want to stop the already playing sound and then start to play the sound of the page he just turned.
I put my little experimental code on the event linked to page turned and I attached here my little test code (I modified slider.hml in the magazine example folder):
var gAudio = null
function loadApp() {
// I omitted the non relevant code part
turned: function(event, page, view) {
disableControls(page);
$(this).turn('center');
$('#slider').slider('value', getViewNumber($(this), page));
if (page == 1) {
$(this).turn('peel', 'br');
}
if (gAudio) {
gAudio.stop();
}
// [MM] it is just a test, I will have a sound file every 2 pages
gAudio = new Audio('paudio/' + page.toString() + '.mp3');
gAudio.play();
},
I found a solution that simply works, this is the relevant part of code: