所以我有这段代码可以打开我自己制作的“播放器”。但是当播放器打开时没有声音出来,这是以前从未发生过的。可能是什么原因。当用 Chrome 打开时,无论播放器如何打开,无论它会弹出什么,或者链接粘贴到 URL 栏中,都没有声音。你知道吗?
你可以在这里查看我的播放器:http: //newfm.ddns.me:12/ m.player.html
弹出的html代码:
<html>
<head>
<style>
<!--Image is used instead of text, to link page-->
a {
background: url(https://image.ibb.co/cxnuMU/playbutton.png) center no- repeat;
display: block;
width: 44px;
height: 45px;
}
</style>
</head>
<!--Link to the page and size page should be opened in-->
<a href="#" onClick="window.open('http://newfm.ddns.me:12/m.player.html','pagename','resizable,height=640,width=370'); return false;"></a>
在这个播放器中发送声音的是那个“播放按钮”。可能是我需要将 SSL 添加到我的流 url 中吗?
播放按钮的 HTML 代码:
<div class="ex1">
<a id="play-pause-button" class="fa fa-pause"></a>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script>
var audio = new Audio("http://newfmplayer.ddns.net:8000/newfm128.m3u");
$('#play-pause-button').on("click",function(){
if($(this).hasClass('fa-play'))
{
$(this).removeClass('fa-play');
$(this).addClass('fa-pause');
audio.play();
}
else
{
$(this).removeClass('fa-pause');
$(this).addClass('fa-play');
audio.pause();
}
});
audio.onended = function() {
$("#play-pause-button").removeClass('fa-pause');
$("#play-pause-button").addClass('fa-play');
};
</script>
<style media="screen" type="text/css">
@import url(https://cdnjs.cloudflare.com/ajax/libs/font- awesome/4.6.3/css/font-awesome.min.css);
#play-pause-button{
font-size: 50px;
cursor: pointer;
color: black;
position: relative;
left: 150px;
top: 480px;
}
</style>
</div>
</body></html>
我还测试了它是否可以使用简单的代码:
<audio controls>
<source src="http://newfmplayer.ddns.net:8000/newfm128.m3u" type="audio/mpeg">
</audio>
它也没有工作。