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.
SC.get() not working when installed with PhoneGap
-
19-10-2022 - |
Frage
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?
Lösung 2
Andere Tipps
You have to use the SC.stream()
function. So, you can do it like this:
SC.initialize({
client_id: "YOUR_CLIENT_ID"
});
SC.stream("/tracks/293", function(sound){
sound.play();
}
And you can do it like this to get tracks from a specific user:
SC.initialize({
client_id: "YOUR_CLIENT_ID"
});
//Select the song in the list you want to play
var songNumber=1;
//Get tracks from a user
SC.get('/users/8030565/tracks/', function(tracks) {
for (var i=0;i<tracks.length; ++i){
tracksList.push(tracks[i]);
}
//Stream a track
SC.stream("/tracks/"+tracksList[songNumber].id, function(sound){
sound.play();
}
}
Hope this helps! Read the docs, it gets simpler after a while.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow