標籤:content 停止 null class pre cli 調用 迴圈 click
/*聲音的js*/$(function () { var file = []; file[‘mp3‘] = ‘../../Content/music/1.mp3‘; audioplayer(‘audioplane‘, file, true); $("#voicebtn").click(function () { if ($(this).hasClass("voiceBtn")) { $(this).removeClass("voiceBtn").addClass("noVoiceBtn"); audioplayer(‘audioplane‘); } else { $(this).removeClass("noVoiceBtn").addClass("voiceBtn"); audioplayer(‘audioplane‘, file, true); } }); });/*加註跟注棄牌全壓其他聲音*/function Voice() { }/* 用法樣本: var file = []; file[‘mp3‘] = ‘1.mp3‘; file[‘ogg‘] = ‘1.ogg‘; // 播放 audioplayer(‘audioplane‘, file, true); // 停止 audioplayer(‘audioplane‘);*//** 音樂播放器 * @param obj 播放器id * @param file 音頻檔案 mp3: ogg: * @param loop 是否迴圈 */ function audioplayer(id, file, loop){ var audioplayer = document.getElementById(id); if(audioplayer!=null) { document.body.removeChild(audioplayer); } if(typeof(file)!=‘undefined‘) { if(navigator.userAgent.indexOf("MSIE")>0) { // IE var player = document.createElement(‘bgsound‘); player.id = id; player.src = file[‘mp3‘]; player.setAttribute(‘autostart‘, ‘true‘); if(loop){ player.setAttribute(‘loop‘, ‘infinite‘); } document.body.appendChild(player); }else{ // Other FF Chome Safari Opera var player = document.createElement(‘audio‘); player.id = id; player.setAttribute(‘autoplay‘, ‘autoplay‘); if (loop) { player.setAttribute(‘loop‘, ‘loop‘); } document.body.appendChild(player); var mp3 = document.createElement(‘source‘); mp3.src = file[‘mp3‘]; mp3.type = ‘audio/mpeg‘; player.appendChild(mp3); var ogg = document.createElement(‘source‘); ogg.src = file[‘ogg‘]; ogg.type = ‘audio/ogg‘; player.appendChild(ogg); } }}
js調用播放音樂