Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

soundcloud API - detect if a track does not exist / SC.Widget.Events.ERROR

Is it possible to detect if a track does not exist using the soundcloud widget?

I tried using the

SC.Widget.Events.ERROR 

event to no avail.

Here is a JSFiddle

like image 453
gregdevs Avatar asked May 03 '26 07:05

gregdevs


1 Answers

I stumbled upon exact the same problem,

SC.Widget.Events.ERROR 

doesn't fire if a track on soundcloud is deleted.

My workaround looks like this:

  var link = "https://soundcloud.com/jaytantrumdesire/tantrum-desire-get-with-it";
  var isDef = SC.get('/resolve', { url: link }, function(track) {
   return track.id;
  });
  if (isDef != undefined) {
    // function to run when track exists
  } else if (isDef == undefined) {
    // function to run when track deleted/not available
  }

Since i work with direct links I check if the direct link has an ID, if it has, the track is available, if doesnt't, the track is not available.

If you are working with the track IDs I guess you could check if the ID has a track title:

  var trackid = "32260824";
  var isDef = SC.get('/tracks/' + trackid, function(track) {
    return track.title; 
  });

To call these functions you must create an app on soundcloud to get a ClientID to use the soundcloud JavaScript SDK. An introduction on how to use it can be found on Soundcloud Developers

First post here, hope this can help someone!

like image 151
haipa Avatar answered May 04 '26 22:05

haipa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!