Better soundcloud loader

This commit is contained in:
Kasper Rynning-Tønnesen
2018-08-29 12:16:12 +02:00
parent b9fd06f072
commit 7a6d34677d
2 changed files with 33 additions and 13 deletions

View File

@@ -7,6 +7,7 @@ if(domain.length > 0 && domain[0] == "client") {
}
var soundcloud_enabled = true;
var local_new_channel = false;
var sc_need_initialization = false;
var hiddenPlaylist = false;
var videoSource;
var dynamicListeners = {};
@@ -235,19 +236,27 @@ window.addEventListener("DOMContentLoaded", function() {
if (tagSC.readyState == "loaded" ||
tagSC.readyState == "complete"){
tagSC.onreadystatechange = null;
if(sc_need_initialization) {
Player.soundcloudReady();
} else {
SC.initialize({
client_id: api_key.soundcloud
}, function() {
});
}
}
};
} else { //Others
tagSC.onload = function(){
if(sc_need_initialization) {
Player.soundcloudReady();
} else {
SC.initialize({
client_id: api_key.soundcloud
}, function() {
});
}
};
} else { //Others
tagSC.onload = function(){
SC.initialize({
client_id: api_key.soundcloud
}, function() {
});
};
}
tagSC.src = "https://connect.soundcloud.com/sdk/sdk-3.3.0.js";
firstScriptTagSC = document.getElementsByTagName('script')[0];

View File

@@ -729,10 +729,20 @@ var Player = {
},
soundcloudReady: function() {
SC.initialize({
client_id: api_key.soundcloud
}, function() {
});
if(SC == undefined && sc_need_initialization) {
sc_need_initialization = true;
return;
}
sc_need_initialization = false;
try {
SC.initialize({
client_id: api_key.soundcloud
}, function() {
});
} catch(e) {
sc_need_initialization = true;
return;
}
beginning = true;
player_ready = true;
if(!durationBegun) {
@@ -999,8 +1009,9 @@ var Player = {
try {
Player.soundcloudReady();
} catch(error) {
console.error(error);
console.error("Seems SoundCloud script isn't correctly loaded. Please reload the page.");
sc_need_initialization = true;
//console.error(error);
//console.error("Seems SoundCloud script isn't correctly loaded. Please reload the page.");
}
} else {
tagSC = document.createElement('script');