2013-03-24 69 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時,音頻「僅適用於 」。

相關問題