Search code examples
javascriptdeezer

Deezer Radio: Track id not in radio


How to achieve that all tracks in Deezer Radio API remain unchanged and therefore playable?

Explanation: I have a Deezer App (HTML+JavaScript, no external libraries) on a Set-Top-Box.

App grabs list of radio trakcs from above mentioned API. It then plays the tracks, fetching the streaming URL for each track from streaming API.

Sometimes the list of radio tracks remains unchanged for many API calls and sometimes the list changes with every call. Why is this so? When a radio track is no longer in radio's list, streaming API returns an error:

{
    error: {
        type: "DataException",
        message: "Track id not in radio",
        code: 800
    }
}

For example, I get a list of 40 tracks for a particular radio, streaming API normally returns full streaming URLs but every 5th or so track fails to play (a.k.a. Deezer API throws above error) it is not because of erroneus API call but because that particular track is not in the original list of 40 tracks anymore... or this is my own assumption at least.

Therefore I am searching for a way to have a fixed list of 40 tracks that would not change until I play all 40 of them and then get the new list. Is that possible or am I missing something?

Thank you!


Solution

  • There is two ways to achieve this with the JavaScript SDK.

    1) You can directly play the radio with DZ.player.playRadio(radio_id)

    2) If your really want a fixed list, you can fetch the track list on http://api.deezer.com/radio/radio_id/tracks then play all the tracks with DZ.player.playTracks(tracks)

    Example:

    DZ.api('/radio/30771/tracks', function(result) {
        var tracks = result.data.map(function(elem) {
            return elem.id;
        });
    
        DZ.player.playTracks(tracks);
    });
    

    EDIT: After discussion in the comment, the solution is just do play directly the track without mentioning the radio_id in the streaming url.