2016-07-08 73 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面板中添加这些行(或'