今天我開始在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>
非常感謝
請參閱 https://stackoverflow.com/questions/28600878/audio-in-html-of-ios-webview-control-doesnot-work/28601508#28601508 – user602570 2017-02-23 10:36:16