My question is identical to this one here, however as the question was never resolved and I can't message PeeHaa privately to ask the answer I'll ask again here.
I've successfully queried the soundcloud api and gotten my the stream_url for each track and added it to all the hrefs of my 360 player (demo here). My code for the elements looks something like this:
<div class="ui360">
<a href="/path/to/an.mp3" data-title="Track title">play "an.mp3"</a>
</div>
I have this script to find all the a tags with data-title attributes and give them the correct href based on the stream_url, but when I try to click the soundmanager icon in the browser and play the track, it just gets redirected to the .mp3 url.
SC.initialize({
client_id: 'MY_CLIENT_ID'
});
SC.get('/playlists/2450655', 'allow_redirects=False', function(playlist) {
var titles = $('.audio .ui360 a').each(function(index){
this.index = index;
});
for (var i = 0; i < playlist.tracks.length; i++) {
var id = '?client_id=MY_CLIENT_ID'
for (var j = 0; j < titles.length; j++) {
if (playlist.tracks[i].title === $(titles[j]).attr('data-title')) {
$(titles[j]).attr('href', playlist.tracks[i].stream_url+id)
}
}
}
});
Does anyone know how to get the correct url for playing tracks hosted on soundcloud in this manner?
My question is identical to this one here, however as the question was never resolved and I can't message PeeHaa privately to ask the answer I'll ask again here.
I've successfully queried the soundcloud api and gotten my the stream_url for each track and added it to all the hrefs of my 360 player (demo here). My code for the elements looks something like this:
<div class="ui360">
<a href="/path/to/an.mp3" data-title="Track title">play "an.mp3"</a>
</div>
I have this script to find all the a tags with data-title attributes and give them the correct href based on the stream_url, but when I try to click the soundmanager icon in the browser and play the track, it just gets redirected to the .mp3 url.
SC.initialize({
client_id: 'MY_CLIENT_ID'
});
SC.get('/playlists/2450655', 'allow_redirects=False', function(playlist) {
var titles = $('.audio .ui360 a').each(function(index){
this.index = index;
});
for (var i = 0; i < playlist.tracks.length; i++) {
var id = '?client_id=MY_CLIENT_ID'
for (var j = 0; j < titles.length; j++) {
if (playlist.tracks[i].title === $(titles[j]).attr('data-title')) {
$(titles[j]).attr('href', playlist.tracks[i].stream_url+id)
}
}
}
});
Does anyone know how to get the correct url for playing tracks hosted on soundcloud in this manner?
Share Improve this question edited May 23, 2017 at 12:08 CommunityBot 11 silver badge asked Oct 17, 2012 at 1:46 satyrsynthsatyrsynth 4191 gold badge5 silver badges14 bronze badges2 Answers
Reset to default 5I know this is an old question, but the problem was driving me up the wall and I finally figured it out, so here's my answer for others:
Soundmanager will work if you specify an mp3 mimetype in the link:
<div class="ui360">
<a type="audio/mp3" href="https://api.soundcloud./tracks/49349198/stream?client_id=YOUR_CLIENT_ID" data-title="Track title">play "an.mp3"</a>
</div>
Why not just use the SoundCloud JavaScript SDK to stream the tracks? Something like:
SC.get('/playlists/2450655', function(playlist) {
$(playlist.tracks).each(function(index, track) {
$('a[href="' + track.stream_url + '"]').click(function(e) {
e.preventDefault();
SC.stream('/tracks/' + track.id, function(sound) {
sound.play();
});
});
});
});
Would that solve your problem, or is there a particular reason you need to resolve the URL?