Question

Today I get started in appmobi. I was developing a small example to deal with sounds.

I just needed to create a handler to play and stop many sounds.

var audioOn = new Audio('sounds/11.mp3'); 
audioOn.play();

This code is working in the xdk simulator, also on android devices, but not in my Iphone 5.

The thing is, if I use tag it works on iphone, but I want to use javascript native api to deal with sounds and more.

I have been trying to deal with it with appmobi player library but it comes without controls to stop, resume etc, thats way I want to use native.

Here is part of javascript code :

<script type="text/javascript">
/* This function runs once the page is loaded, but appMobi is not yet active */
var init = function(){
var alarmButton = document.getElementById("alarmButton");
var on = false;
//var audioOn = new Audio('http://rpg.hamsterrepublic.com/wiki-images/3/3e/Heal8-Bit.ogg');

var audioOn = new Audio('sounds/11.mp3'); 
audioOn.addEventListener('ended', function() {
this.play();
}, false);

var but = function(){
alert("but");
alert(on);
alert(audioOn);

if(!on){
on = true;
audioOn.currentTime = 0;
audioOn.play(); 
}
else{
on = false;
audioOn.pause(); 
}
}
//alarmButton.addEventListener("click",but,false);
alarmButton.addEventListener("touchstart",but,false);
alarmButton.addEventListener("tap",but,false);

};

window.addEventListener("load",init,false);

/* This code prevents users from dragging the page */
var preventDefaultScroll = function(event) {
event.preventDefault();
window.scroll(0,0);
return false;
};
document.addEventListener('touchmove', preventDefaultScroll, false);

/* This code is used to run as soon as appMobi activates */
var onDeviceReady=function(){
//Size the display to 768px by 1024px
AppMobi.display.useViewport(768,1024);
//hide splash screen
AppMobi.device.hideSplashScreen(); 
};

document.addEventListener("appMobi.device.ready",onDeviceReady,false);

function echo(){
alert("clicked");
}

</script>

Thanks a lot

Was it helpful?

Solution

It seems like its not appmobi issue.

I think appmobi lab app for iphone uses safari mobile to run the html5 tests.

So its a safari mobile affair.

It seems play() work when launched by an onclick event. See http://groups.google.com/group/iphonewebdev/browse_thread/thread/91e31ba7ae25e6d4?hl=en

Need to perform some tests...

OTHER TIPS

I have to try this:

http://www.schillmania.com/projects/soundmanager2/

Supporting HTML5 audio can be tedious in modern browsers, let alone legacy ones. With real-world visitors using browsers ranging from mobile Safari to IE 6 across a wide range of devices, there can be many support cases to consider.

SoundManager 2 gives you a single, powerful API that supports both new and old, using HTML5 audio where supported and optional Flash-based fallback where needed. Ideally when using SoundManager 2, audio "just works."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top