Currently I'm having a web page that can play updated audio clips store locally in a folder produced from some other service. The audio that I play when button is being pressed is the previous audio clips(probably due to cache?). Unless i manually close the tab and reopen another tab.
Is it possible to let the or JS function to load the audio file every time before play
<td style="position:relative; top:1px;">
<input id="scream"
type="button"
class="btn"
onclick="play_single_sound()">
</td>
<audio src="{{url_for('static', filename='/screams/new_scream.wav')}}" id="audiotag1" autoplay="autoplay" preload="metadata"/>
<source src="/screams/new_scream.wav" type="audio/mpeg">
</audio>
<script type="text/javascript">
#FIRST METHOD
<!-- var song = document.getElementById('audiotag1')-->
<!-- function play_single_sound() {-->
<!-- song.play();-->
<!-- }-->
#SECOND METHOD
window.play_single_sound = function() {
document.getElementById('audiotag1').play();
}
</script>
I have also attempted with loading audio as instance inside JS, as follows:
var song = new Audio ("../screams/new_scream.wav");
song.preload="auto";
song.play();
All the above methods doesn't allow me to play song clip that change dynamically in a static folder. Any advice ?
Remove autoplay attribute
<audio src="{{url_for('static', filename='/screams/new_scream.wav')}}" id="audiotag1" preload="metadata"/>