emptyfm

Listen to your favorite FM Radio station from your browser.
Log | Files | Refs | README | LICENSE

commit 1437f276f0d321f2869d56e6b1bb6e9f51547997
parent cbc6a366cc7068675f0c6644991168ea728bf151
Author: Nirmal Kumar R <tildezero@gmail.com>
Date:   Tue, 19 Mar 2024 19:29:50 +0530

Support videojs for various formats

Diffstat:
Memptyfm.js | 26+++++++++++++++++++++++---
Mindex.html | 6++----
2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/emptyfm.js b/emptyfm.js @@ -33,13 +33,16 @@ async function fetchFMStations() { let fmList = document.getElementById("fmlist"); - fmList.InnerHTML = ""; + fmList.innerHTML = ""; for (var k in stations) { let atag = document.createElement("a"); atag.className = "fmitem"; atag.href = stations[k].url; atag.innerText = stations[k].name; - atag.onclick = () => alert(atag.href); + atag.onclick = (e) => { + e.preventDefault(); + changeSource(atag.href); + } fmList.appendChild(atag); } @@ -47,10 +50,27 @@ async function fetchFMStations() { function changeSource(url) { player = videojs('emptyfm'); - player.src({ type: 'application/x-mpegURL', src: url }); + mediaType = fetchMediaType(url); + player.src({ type: mediaType, src: url }); player.play(); } +function fetchMediaType(url) { + last = url.split("/").pop(); + switch (last) { + case "stream": + return "audio/mpeg"; + default: + ext = last.split(".").pop(); + switch (ext) { + case "m3u8": + return "application/x-mpegURL"; + default: + return "audio/mpeg"; + } + } +} + function listCountries() { fetch('./iso-3166-1-alpha2-countrycode.json') .then((response) => response.json()) diff --git a/index.html b/index.html @@ -71,7 +71,7 @@ } #emptyfm { - margin-left: 500px; + margin-left: 600px; } </style> </head> @@ -100,9 +100,7 @@ </div> </header> - <div class="fmstations" id="fmlist"> - <a href="/">Kodai FM</a> - </div> + <div class="fmstations" id="fmlist"></div> <video id="emptyfm"