0

Right now I have a very basic HTML5 Audio player that play from webradio. I use a old iPad to play the music but also to show some information from a webpage. The problem is that is happen sometime the wifi and the old iPad does not like to stay connect so it disconnect and reconnect and then the player stop play the webradio. I need somehow a script that notice in real time or every 1 min if the radio is not running and restart the player for me. I guess I can use Javascript but have search a Little and not find any good idea and it also have to work in Chrome. It looks that some javaScript does not work in specific webbrowser

Cazz
  • 51
  • 7

1 Answers1

0

Basically, your <audio> element will dispatch an error event. Just listen for that and then retry. You could also listen to the progress event to see when it starts receiving again and then call play from there. It'd be something roughly like this:

const audio = getAudioElement();

audio.addEventListener('error', () => { playing = false; /* handle error */ });
audio.addEventListener('progress', () => { 
  if (!playing) { 
    audio.play(); 
    playing = true;
  } 
});
samanime
  • 25,408
  • 15
  • 90
  • 139
  • Thanks but I have now try and I have done something wrong. Is same problem as Before and here is that I have done http://c-media.se/radio.txt (I did create a textfile because I did read the help alot but have problem here to form the code right. – Cazz Jun 13 '18 at 21:49