我在javascript中设置了一个音频播放器,但是当我想要用户检测到onclick
时,代码会中断并且所有内容都会导致Loading...
消息,并且实际播放器上没有声音
这是代码:
/*else if (document.getElementById("batar-btn").onclick = function())
{
player.src = 'http://live.shockradio.co.uk/ob';
}*/
我希望在为用户加载页面后更改流地址,并单击带有batar-btn
ID的按钮。 如何使用上述代码执行此操作?
player = document.createElement("audio");
if (typeof player.canPlayType === "function" && player.canPlayType("audio/mpeg") !== "")
{
backend = 'html';
var format = "mp3";
player = new Audio();
if (isMobile)
{
$('#muteIcon').css('display', 'none');
$('#playIcon').css('display', 'inline-block');
if (player.canPlayType("audio/mp4; codecs=\"mp4a.40.5\"") !== "")
{
player.src = 'http://live.shockradio.co.uk/mobile';
}
else
{
player.src = 'http://live.shockradio.co.uk/mp3';
}
}
/*else if (document.getElementById("batar-btn").onclick = function())
{
player.src = 'http://live.shockradio.co.uk/ob';
}*/
else
{
player.src = 'http://live.shockradio.co.uk/mp3';
}
player.mozAudioChannelType = 'content';
player.addEventListener("playing", showStopIcon, false);
player.addEventListener("pause", showPlayIcon, false);
player.addEventListener("ended", showPlayIcon, false);
player.load();
player.play();
}
else
{
backend = 'flash';
swfobject.embedSWF('swf/player.swf', 'flashPlayer', '1', '1', '10');
document.title = '\u25b6 Shock Radio Player';
_gaq.push(['_trackEvent', 'Player', 'Play']);
}
答案 0 :(得分:0)
应检查它的功能如下:
else if (typeof document.getElementById("batar-btn").onclick === 'function')
{
player.src = 'http://live.shockradio.co.uk/ob';
}