/*声音的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); } } }
时间: 2024-10-13 00:33:08