js調用播放音樂

來源:互聯網
上載者:User

標籤: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調用播放音樂

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.