這回答我也是醉了。
今天同樣遇到這個問題。
.play()在安卓可以使用,在ios微信裡面播放mp3沒有
② html5多次用js播放audio之後就沒有聲音了. 重新刷新之後又好了
推薦你採用控制
既然看到送你一個demo吧,自行研究,應該都很詳細了
<!doctypehtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width,initial-scale=1user-scalable=0"/>
<linkrel="shortcuticon"href="img/logo.png">
<title>html5audio音頻播放</title>
<style>
*{margin:0;padding:0;}
body{-webkit-tap-highlight-color:rgba(0,0,0,0);font-family:"微軟雅黑"}
h1{width:100%;font-size:1.5em;text-align:center;line-height:3em;color:#47c9af;}
#audio{width:100%;}
#control{width:150px;height:150px;line-height:150px;text-align:center;border-radius:200px;border:none;color:#fff;margin-top:-75px;margin-left:-75px;left:50%;top:50%;position:absolute;box-shadow:#888008px;}
.color_gray{background:#e4e4e4}
.hide{display:none;}
.show{display:block;}
.play{background:#f06060;}
.pause{background:skyblue}
/*進度條樣式*/
.progressBar{width:100%;height:10px;margin:30pxauto30pxauto;position:absolute;left:0;bottom:35px;}
.progressBardiv{position:absolute;}
.progressBar.progressBac{width:100%;height:10px;left:0;top:0;background:#e4e4e4;}
.progressBar.speed{width:100%;height:10px;left:-100%;background:#f06060;}
.progressBar.drag{width:30px;height:30px;left:0;top:-10px;background:skyblue;opacity:0.8;border-radius:50px;box-shadow:#fff005px;}
/*時間樣式*/
#time{width:100%;height:20px;position:absolute;left:0;bottom:30px;color:#888;}
.tiemDetail{position:absolute;right:10px;top:0;}
#songInfo{overflow:hidden;width:200px;height:50px;line-height:50px;text-align:center;color:#34495e;margin-top:-25px;margin-left:-100px;left:50%;top:70%;position:absolute;}
.shareImg{position:absolute;left:100000px;}
</style>
</head>
<body>
<script>
$(function(){
getSong();
})
//獲取歌曲鏈接並插入dom中
functiongetSong(){
varaudio=document.getElementById("audio");
audio.src="
audio.loop=true;//歌曲循環
playCotrol();//播放控制函數
}
//點擊播放/暫停
functionclicks(){
varaudio=document.getElementById("audio");
$("#control").click(function(){
if($("#control").hasClass("play")){
$("#control").addClass("pause").removeClass("play");
audio.play();//開始播放
dragMove();//並且滾動條開始滑動
$("#control").html("暫停播放");
}else{
$("#control").addClass("play").removeClass("pause");
$("#control").html("點擊播放");
audio.pause();
}
})
}
//播放時間
functiontimeChange(time,timePlace){
vartimePlace=document.getElementById(timePlace);
//分鍾
varminute=time/60;
varminutes=parseInt(minute);
if(minutes<10){
minutes="0"+minutes;
}
//秒
varsecond=time%60;
seconds=parseInt(second);
if(seconds<10){
seconds="0"+seconds;
}
varallTime=""+minutes+""+":"+""+seconds+""
timePlace.innerHTML=allTime;
}
//播放事件監聽
③ 微信jssdk錄制的音頻,下載到伺服器,在微信瀏覽器中怎麼調用播放
兄弟解決沒有,有沒有方法,我這邊是轉換成mp3,但是轉換mp3出現奇葩問題,被自動剪切了一部分,本地測試都正常,坑死了
④ 如何用js控制html頁面中音頻的播放(360瀏覽器)
你的play方法是html5的方法吧,可能是你360的版本低
html5現在還是有很多比較老的版本瀏覽器是不兼容的
一般html播放音頻兼容比較好的是用插件
<ahref="song.mp3">PlaySound</a>
<scripttype="text/javascript"src="http://mediaplayer.yahoo.com/js">
</script>
⑤ 想用怎麼用js實現播放音頻。
1、播放音樂需要區分瀏覽器,來使用不用的對象來播放音樂
2、在播放控制上要有【播放】和【停止】來控制音樂的播放
基於以上思路,代碼如下:
<SCRIPTtype="text/javascript">
if(-1!=navigator.userAgent.indexOf("MSIE"))
{
//不是微軟IE瀏覽器,則調用Flash來播放音樂
document.write('<OBJECTid="Player"');
document.write('classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"');
document.write('width=0height=0><paramname="URL"value="a.mp3"/><paramname="AutoStart"value="false"/></OBJECT>');
}
else
{
//是微軟IE瀏覽器,則調用微軟的Player對象來直接播放音樂
document.write('<OBJECTid="Player"');
document.write('type="application/x-ms-wmp"');
document.write('autostart="false"src="a.mp3"width=0height=0></OBJECT>');
}
</SCRIPT>
<inputtype=buttonvalue="播放"onclick="Player.controls.play();"/>
<inputtype=buttonvalue="停止"onclick="Player.controls.stop();"/>