I have this linked problem when I try to get a broadcasted audio via a pause-play image.
<audio id="myAudio" src="http://ip:port/;" autoplay>
<!-- Autoplay does not work every time in Chrome -->
</audio>
<img id="pause_play" src="pause.png" onClick="playPause()"/>
<script>
function playPause(){
var audio = document.getElementById('myAudio');
// when audio is paused
if(audio.paused){
audio.src="http://ip:port/;"; // often cancelled
audio.load();
audio.play();
document.getElementById('pause_play').src="pause.png"; // change image
}
// when audio is playing, we set it to pause (this always work)
else{
audio.pause();
audio.src=false;
audio.load();
document.getElementById('pause_play').src="play.png"
}
}
</script>
It works fine on firefox, but Chrome often cancels my requests. Player image is changing but no sound is playing; and that is not cool.
How to check if audio is really playing ? So that pause play will change on the right time.