add support for older browsers
This commit is contained in:
parent
a385935c7c
commit
dff4ecc42c
23
radio.js
23
radio.js
|
@ -77,11 +77,30 @@ function startStation(new_station) {
|
||||||
if (tuner.player != null) tuner.player.stop();
|
if (tuner.player != null) tuner.player.stop();
|
||||||
// Start player using IcecastMetadataPlayer for the metadata.
|
// Start player using IcecastMetadataPlayer for the metadata.
|
||||||
// Use ?+date for avoiding problems with cache.
|
// Use ?+date for avoiding problems with cache.
|
||||||
|
try {
|
||||||
|
document.body.classList.remove('old');
|
||||||
tuner.player = new IcecastMetadataPlayer(new_station.listen_url+"?"+Date.now(), {
|
tuner.player = new IcecastMetadataPlayer(new_station.listen_url+"?"+Date.now(), {
|
||||||
onMetadata: (metadata) => {updateMetadata(metadata.StreamTitle.decodeHTMLEntity());},
|
onMetadata: (metadata) => {
|
||||||
metadataTypes: ["icy"],
|
console.log(metadata);
|
||||||
|
let title = metadata.StreamTitle??(metadata.ARTIST+" - "+metadata.TITLE);
|
||||||
|
updateMetadata(title.decodeHTMLEntity());
|
||||||
|
let metasplit = metadata.StreamTitle.split(" - ");
|
||||||
|
if ('mediaSession' in navigator) { navigator.mediaSession.metadata = new MediaMetadata({ title: metadata.TITLE??metasplit[1], artist: metadata.ARTIST??metasplit[0] }) };
|
||||||
|
},
|
||||||
|
metadataTypes: ["icy", "ogg"],
|
||||||
icyCharacterEncoding: "iso-8859-1"
|
icyCharacterEncoding: "iso-8859-1"
|
||||||
});
|
});
|
||||||
|
} catch(error) {
|
||||||
|
document.body.classList.add('old');
|
||||||
|
console.error(error);
|
||||||
|
tuner.player = { audioElement: null };
|
||||||
|
tuner.player.audioElement = new Audio();
|
||||||
|
tuner.player.audioElement.src = new_station.listen_url+"?"+Date.now();
|
||||||
|
updateMetadata(new_station.listen_url);
|
||||||
|
|
||||||
|
tuner.player.play = function() { tuner.player.audioElement.play(); };
|
||||||
|
tuner.player.stop = function() { tuner.player.audioElement.pause(); tuner.player.audioElement.src = ''; };
|
||||||
|
}
|
||||||
|
|
||||||
// Start new context with analysers
|
// Start new context with analysers
|
||||||
// Check if channels is only 1. If not, we assume stereo.
|
// Check if channels is only 1. If not, we assume stereo.
|
||||||
|
|
Reference in New Issue
Block a user