我曾尝试使用 html5 sudio 标签播放音频文件(我尝试过 .wav 和 .mp3 格式)。但是,当我在 Eclipse 中为 android Gingerbread 在模拟器上运行项目时,当我单击我创建的播放按钮时,它似乎没有播放。我正在使用安卓 4.0 API。为什么会这样?我错过了任何阻止模拟器播放音调的东西吗?
下面是我的html代码:
$('#page-home').live('pageinit', function(event){
$('.api-div').hide();
$('.api-div#api-intro').show();
$('#intro').click(function() {
$('.api-div').hide();
$('.api-div#api-intro').show();
$.mobile.silentScroll(0);
});
$('div ul li a').click(function(event) {
event.preventDefault();
//alert('clicked : ' + $(this).attr('id'));
var attrId = $(this).attr('id');
if (attrId.indexOf("click") !== 0) {
return;
}
var api = '#api' + attrId.substring(attrId.indexOf('-'));
// hide all div's, show only this one
$('.api-div').hide();
$(api).show();
// if small screen and portrait - close after tap
var disp = $('ul #listdivider').css("display");
//alert(disp + ' : ' + api);
if (disp === 'none') {
$('div.ui-collapsible').trigger("collapse");
} else {
$.mobile.silentScroll(0);
}
});
$('#listdivider').click(function(event) {
event.preventDefault();
$('.api-div').hide();
$('.api-div#api-intro').show();
$.mobile.silentScroll(0);
});
$("#playaudio").live('tap', function() {
var src = 'tone1K.mp3';
// Note: two ways to access media file: web and local file
//var src = 'http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3';
// local (on device): copy file to project's /assets folder:
// var src = '/android_asset/spittinggames.m4a';
playAudio(src);
});
$("#pauseaudio").live('tap', function() {
pauseAudio();
});
$("#stopaudio").live('tap', function() {
stopAudio();
});
});
下面是我在点击时播放音调的 javascript:
$('#page-home').live('pageinit', function(event){
$('.api-div').hide();
$('.api-div#api-intro').show();
$('#intro').click(function() {
$('.api-div').hide();
$('.api-div#api-intro').show();
$.mobile.silentScroll(0);
});
$('div ul li a').click(function(event) {
event.preventDefault();
//alert('clicked : ' + $(this).attr('id'));
var attrId = $(this).attr('id');
if (attrId.indexOf("click") !== 0) {
return;
}
var api = '#api' + attrId.substring(attrId.indexOf('-'));
// hide all div's, show only this one
$('.api-div').hide();
$(api).show();
// if small screen and portrait - close after tap
var disp = $('ul #listdivider').css("display");
//alert(disp + ' : ' + api);
if (disp === 'none') {
$('div.ui-collapsible').trigger("collapse");
} else {
$.mobile.silentScroll(0);
}
});
$('#listdivider').click(function(event) {
event.preventDefault();
$('.api-div').hide();
$('.api-div#api-intro').show();
$.mobile.silentScroll(0);
});
$("#playaudio").live('tap', function() {
var src = 'tone1K.mp3';
// Note: two ways to access media file: web and local file
//var src = 'http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3';
// local (on device): copy file to project's /assets folder:
// var src = '/android_asset/spittinggames.m4a';
playAudio(src);
});
$("#pauseaudio").live('tap', function() {
pauseAudio();
});
$("#stopaudio").live('tap', function() {
stopAudio();
});
});