我有以下html代码段:
re.findall('({0})?(,{0})*'.format(<your_pattern>), <some_string>)
但是当我点击PLAY按钮时,它似乎没有播放音频。 我怎么能这样做?
答案 0 :(得分:0)
您永远不会获取音频文件并将其分配给变量。在您的情况下,audioElement.play();
没有播放任何内容,因为它与任何内容都没有关联。
我的方法与你的方法略有不同。我决定直接将音频文件放在JavaScript中。您可以查看下面的内容:
纯JavaScript:
function Play_Audio(){
var audioElement = document.createElement("audio");
audioElement.src = "https://raw.githubusercontent.com/Metastruct/garrysmod-chatsounds/master/sound/chatsounds/autoadd/snoop_dogg/hold%20up%20wait.ogg";
document.getElementById("Play_Button").addEventListener("click", function(music){
audioElement.play();
}, false);
}
Play_Audio();
<button id="Play_Button">Play</button>
jQuery的:
$(document).ready(function(){
var audioElement = document.createElement("audio");
audioElement.src = "https://raw.githubusercontent.com/Metastruct/garrysmod-chatsounds/master/sound/chatsounds/autoadd/snoop_dogg/hold%20up%20wait.ogg";
$('#Play_Button').click(function(){
audioElement.play();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="Play_Button">Play</button>
从音频标签中获取声音:
document.getElementById("Play").addEventListener("click", function(music){
var audioElement = document.getElementById("Audio");
audioElement.play();
}, false);
<audio id="Audio" controls>
<source src="https://raw.githubusercontent.com/Metastruct/garrysmod-chatsounds/master/sound/chatsounds/autoadd/snoop_dogg/hold%20up%20wait.ogg" type="audio/ogg">
</audio>
<div id="Play">Play Button</div>
PS:我花了更多的时间来寻找合适的音频,而不是写片段....我想,我有问题!