您好,登錄后才能下訂單哦!
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset = utf-8"> </head> <script type="text/javascript" charset="utf-8"> function pageLoaded(){ var canvas = document.getElementById('testcanvas');//得到畫布 var context = canvas.getContext('2d');//得到繪圖環(huán)境 參數(shù)為繪圖環(huán)境的類型 //檢查音頻支持 var audiotest = document.createElement('audio'); var mp3Support,oggSupport,wavSupport; if(audiotest.canPlayType){ /* MP3格式:字符串a(chǎn)udio/mpeg;支持的瀏覽器:IE9+、Chrome Vorbis格式:字符串a(chǎn)udio/ogg,codecs=”vorbis”;支持的瀏覽器:Firefox 3.5+、Chrome、Opera 10.5+ WAV格式:字符串a(chǎn)udio/wav,codecs=”1”;支持的瀏覽器:Firefox 3.5+、Opera 10.5+、Chrome */ mp3Support = "" != audiotest.canPlayType('audio/mpeg'); oggSupport = "" != audiotest.canPlayType('audio/ogg; codecs = "vorbis"'); wavSupport = "" != audiotest.canPlayType('audio/wav,codecs="1"'); } else{ mp3Support = false; oggSupport = false; wavSupport = false; } var soundFileExtn = oggSupport?'.ogg':mp3Support?'.mp3':wavSupport?'.wav':undefined; if(soundFileExtn){ //動(dòng)態(tài)加載audio文件 var audio = new Audio(); //等待音頻文件加載完成 然后再播放 audio.addEventListener('canplaythrough',function(){ audio.play(); }); audio.src="/testmusic/8466/8466"+soundFileExtn; } } </script> <body onload="pageLoaded();"> <canvas width="1200" height="480" id="testcanvas" > </canvas> <audio src="/testmusic/8466/8466.wav" controls = "controls" > </audio> <audio src="/testmusic/8466/8466.mp3" controls="controls2"> </audio> <audio controls="controls3"> <!--瀏覽器會(huì)選擇第一個(gè)支持的格式 音頻格式 MINE-type MP3 audio/mpeg Ogg audio/ogg Wav audio/wav --> <source src="/testmusic/8466/8466.wav" type="audio/wav"> <source src="/testmusic/8466/8466.mp3" type="audio/mpeg"> </audio> </body> </html>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。