Skip to content

Instantly share code, notes, and snippets.

@marco79cgn
Created April 16, 2018 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marco79cgn/25719af25ba7b73b84c72947c84b6c46 to your computer and use it in GitHub Desktop.
Save marco79cgn/25719af25ba7b73b84c72947c84b6c46 to your computer and use it in GitHub Desktop.
The simplest way to play a radio paradise flac stream using howlerjs
var flacApiBaseUrl = 'https://api.radioparadise.com/api/get_block?bitrate=4&info=true';
var flacApiNextEventUrl = 'https://api.radioparadise.com/api/get_block?bitrate=4&info=true';
var nextStream;
function getNextEvent(callback) {
const xhr = new XMLHttpRequest();
xhr.open('get', 'https://cors-anywhere.herokuapp.com/'+flacApiNextEventUrl, true);
xhr.onload = function(e) {
var data = JSON.parse(this.response);
nextStream = data.url+'?src=alexa';
flacApiNextEventUrl = flacApiBaseUrl + '&event=' + data.end_event;
callback();
}
xhr.send();
}
function playStream() {
var stream = new Howl({
src: [nextStream],
ext: ['flac'],
autoplay: true,
html5: true,
onend: function() {
getNextEvent(playStream);
}
});
stream.play();
}
getNextEvent(playStream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment