2013-03-24 70 views
0

今天我开始在appmobi。我正在开发一个小例子来处理声音。AppMobi,html5声音工作在模拟器和android但不在iphone中

我只需要创建一个处理程序来播放和停止很多声音。

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

该代码是工作在XDK模拟器,同时在Android设备上,而不是在我的iPhone 5

的事情是,如果我使用的标签它适用于iPhone,但我想用用于处理声音和更多内容的JavaScript本机API。

我一直试图用appmobi播放器库处理它,但它没有控制停止,恢复等,这就是我想要使用本机。

下面是JavaScript代码的一部分:

<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> 

非常感谢

+0

请参阅 https://stackoverflow.com/questions/28600878/audio-in-html-of-ios-webview-control-doesnot-work/28601508#28601508 – user602570 2017-02-23 10:36:16

回答

0

好像它不是appmobi问题。

我认为iphone的appmobi实验室应用程序使用safari mobile来运行html5测试。

因此它是一个野生动物园移动事务。

看起来play()是由onclick事件启动的。见http://groups.google.com/group/iphonewebdev/browse_thread/thread/91e31ba7ae25e6d4?hl=en

需要进行一些测试......

+0

是,英特尔的JavaScript API(HTTP ://www.html5dev-software.intel.com/documentation/jsAPI/index.html)仅适用于使用Cloud Build系统构建的移动混合应用程序的上下文。如果您要在Mobile Safari中运行该Web代码,则无法访问appMobi库对象。 – profMobi 2013-03-25 15:00:36

0

我要试试这个:

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

支持HTML5音频可以在现代浏览器的繁琐,更不用说 继承性。随着真实世界的访问者在各种设备上使用浏览器(范围从 移动版Safari到IE 6),可以考虑使用许多支持案例。

SoundManager 2为您提供了一个功能强大的API,它支持新的 和旧的,使用HTML5音频,在需要的地方支持和可选的基于Flash的 回退。理想情况下,使用SoundManager 2时,音频“仅适用于 ”。

相关问题