ioscordovasoundcloud

SC.get() not working when installed with PhoneGap


I'm attempting to use the SoundCloud API to stream songs, and everything works fine through the browser, but when I attempt to package it with PhoneGap and install it on a phone it no longer works.

The problem seems to be with the SC.get() function. SC.initialize() is working fine, but when I try to get tracks it returns 0 results every time when installed on a phone. This is the code I am using:

SC.get('/tracks', {q: query, filter: 'streamable' }, function(tracks){

            Ext.each(tracks, function(track){
                if(track.streamable){
                    results.push(track);
                }
            });

            if(results.length > 0){
                var tracksStore = Ext.getStore('Tracks');
                tracksStore.removeAll();
                tracksStore.sync();
                tracksStore.setData(results);
            }
            else
            {
                Ext.Msg.alert('No tracks found!', 'Try something different.');
            }
    
        });

This function is called right after the initialize function. Any ideas?


Solution

  • The problem was that nothing was being returned when it was installed on a phone, SC.get just would not return any tracks so it certainly couldn't stream them. It turns out, for whatever reason, when installing on a phone through phonegap you have to use the full path: api.soundcloud.com/tracks and not just /tracks/ otherwise it wont work. Not sure why this is the case, but this fixed it for me.