2016-07-08 75 views

回答

0

HTML5音頻標籤

<audio> 

定義聲音內容

<source> 

定義多種媒體資源媒體元素,例如和

所以,你應該更改您的代碼:

<audio controls width="50" height="50"> 
     <source src="http://hi5.1980s.fm/;"> 
    </audio> 

https://jsfiddle.net/66opsn9b/2/

+0

你可以告訴我它使用OnClick嗎? https://jsfiddle.net/66opsn9b/1/該視頻適用於OnClick。 – htmlcsscoding

+0

它已經有控件可以播放和暫停......不需要定義「onclick」事件。檢查小提琴:https://jsfiddle.net/66opsn9b/2/ –

+0

我希望它使用OnClick,就像視頻一樣。 https://jsfiddle.net/66opsn9b/1/它只是音頻,而不是視頻,這是不可能的?或者你不知道該怎麼做? – htmlcsscoding

0

我實現了一個代碼,我認爲它可能滿足您的要求

使用單按鈕

<html> 
 
<head> 
 
<title>Audio Streaming</title> 
 
</head> 
 
<body> 
 
<input type="button" onclick="playPauseAudio()" value="Play" id="PlayButton" /><br> 
 
<audio id="myAudio" style="Visibility:hidden"> 
 
    <source src="http://hi5.1980s.fm/;"> 
 
</audio> 
 

 
<script> 
 
var audio = document.getElementById("myAudio"); 
 

 
var flg = true; 
 

 
function playPauseAudio() { 
 
    if(flg == true) { 
 
    audio.play(); 
 
    document.getElementById("PlayButton").value = "Pause"; 
 
    flg = false; 
 
    } else { 
 
    audio.pause(); 
 
    document.getElementById("PlayButton").value = "Play"; 
 
    flg = true; 
 
    } 
 
} 
 

 
</script> 
 
</body> 
 
</body> 
 
</html>

使用兩個按鈕

<html> 
 
<head> 
 
<title>Audio Streaming</title> 
 
</head> 
 
<body> 
 

 
<button onclick="playAudio()" type="button">Play Audio</button> 
 
<button onclick="pauseAudio()" type="button">Pause Audio</button><br> 
 

 
<audio id="myAudio" style="Visibility:hidden"> 
 
    <source src="http://hi5.1980s.fm/;"> 
 
</audio> 
 

 
<script> 
 
var audio = document.getElementById("myAudio"); 
 

 
function playAudio() { 
 
    audio.play(); 
 
} 
 

 
function pauseAudio() { 
 
    audio.pause(); 
 
} 
 
</script> 
 
</body> 
 
</body> 
 
</html>

+0

視頻如何工作,但音頻不?像這樣設置?

+0

你期待在一個單一的按鈕? –

+0

它究竟是如何與視頻一起工作的,只是音頻而已。 – htmlcsscoding

0

真的在你的榜樣,唯一的區別是音頻沒有高度/寬度。加這個:

audio { 
width: 100px; 
height: 20px; 
display: block; 
} 

它播放點擊。

+0

如果看起來不是這樣,它不是相同的代碼。

+0

在我的答案中,在css面板中添加這些行(或'