Audio with PLS player

This commit is contained in:
Marc 2018-12-26 11:19:14 +01:00
parent 6fb7e7bc78
commit 90024b3e20
2 changed files with 75 additions and 4 deletions

View File

@ -51,9 +51,9 @@
Resoluciones disponibles
<br>
<em id="video-resolution"></em>
<p id="extra-video-info" style="display: block"></p>
</div>
</div>
<div id="audio" style="margin-top: 15px">
<p class="lead">
Reproductor de Radio
@ -74,7 +74,20 @@
<p class="lead">Información de la reproducción</p>
Formatos soportados
<br>
<em>aac</em>, <em>mp3</em>, <em>nsv</em>, <em>audio/mpeg</em>
<em>aac</em>, <em>mp3</em>, <em>nsv</em>, <em>audio/mpeg</em>, <em>pls</em>(Beta)
<div id="extra-audio-info-div" style="display: none; padding-top: 20px">
<button class="btn btn-secondary" type="button" data-toggle="collapse"
data-target="#collapseAlternativas"
aria-expanded="false" aria-controls="collapseAlternativas">
URLs alternativas
</button>
<div class="collapse" id="collapseAlternativas">
<div class="card card-body">
<p id="extra-audio-info"></p>
</div>
</div>
</div>
</div>
</div>
</div>
@ -140,8 +153,15 @@
}
function reproduceAudio(channelToReproduce) {
console.log("Reproducing audio: " + channelToReproduce);
if (channelToReproduce.includes("pls")) {
getURLsFromPLS(channelToReproduce, reproducePLSFromUrl);
} else {
reproduceAudioFromUrl(channelToReproduce);
}
}
function reproduceAudioFromUrl(channelToReproduce) {
console.log("Reproducing audio: " + channelToReproduce);
var audioSource = document.getElementById('audio-controller');
var audioPlayer = document.getElementById('audio-player');
@ -160,6 +180,11 @@
}
}
function reproducePLSFromUrl(data) {
reproduceAudioFromUrl(data[0]);
updateExtraAudioInfo("pls_more_url_available", data);
}
function updateResolution(resolutions) {
console.log("Resoluciones: " + resolutions);
@ -176,6 +201,21 @@
document.getElementById("video-resolution").innerHTML = "";
}
function updateExtraAudioInfo(type, data) {
console.log("Extra info type: " + type);
console.log("Extra info data: " + data);
var textToAdd = "";
if (type == "pls_more_url_available") {
for (i = 0; i < data.length; i++) {
textToAdd += data[i] + "<br>";
}
}
document.getElementById("extra-audio-info").innerHTML = textToAdd;
document.getElementById("extra-audio-info-div").style.display = "block";
}
</script>
</body>
</html>

View File

@ -1,3 +1,26 @@
function getURLsFromPLS(sUrl, fn_callback) {
var from = "http://provisioning.streamtheworld.com/pls/CADENADIAL.pls";
$.get(from, function(data) {
$response = data.split("\n");
$urls=[];
$.each($response, function( index, value ) {
$line_separated_value = value.split("=");
if ($line_separated_value.length > 1 && $line_separated_value[1].indexOf("http") != -1) {
$urls.push($line_separated_value[1]);
}
});
fn_callback($urls)
//$.each($urls, function( index, value ) {
// if (checkIfWebsiteWorks(value)) {
// fn_callback(value);
// break;
// }
//});
});
};
function getResolution(from, fn_callback) {
$.get(from, function(data) {
$response = data.split("\n");
@ -29,4 +52,12 @@ function getUrlParameter(sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
};
// Check an URL is valid or broken
// TODO: For streams if it works it keeps loading infinite time
function checkIfWebsiteWorks(sUrl){
$.get(sUrl, function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
}