Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Create a Soundcloud playlist ( set ) using javascript?

I am trying to use Soundcloud api for my application where user can create his/her own playlist of track . As a test case the example I am testing is almost exactly taken from the Soundcloud dev docs. below is my code

<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
// initialize client with app credentials
SC.initialize({
  client_id: 'MY_CLIENT_ID',
  redirect_uri: 'http://localhost.local/~****/sc/callback.html'
});

// initiate auth popup and create new playlist
SC.connect(function() {
    SC.get('/me', function(me) {
        console.log(me.username);
    });

    var tracks = [12573606].map(function(id) { return { id: id }; });
    SC.post('/playlists', {
        playlist: { title: 'My Playlist', tracks: tracks }
    });
});

I already searched so many thing's in google but nothing helped me, actually i need temporary playlist so when user logout or close the browser playlist also delete . Any help would be appreciable.. thanx

like image 925
Vivek Singh Avatar asked Jul 13 '15 08:07

Vivek Singh


People also ask

How do I make my own playlist on SoundCloud?

You can make a playlist on SoundCloud using the platform's mobile app or desktop website, and it's a great way to save and organize your favorite music. To make a SoundCloud playlist, click or tap the ellipsis icon below any track and then select "Add to playlist."

Can you make playlists on SoundCloud for free?

SoundCloud playlists allow you to organize your favorite music tracks for your enjoyment or for sharing with others online. Anyone can create a playlist on SoundCloud for free by using the SoundCloud app or website. Plus, there's a variety of customization options available.

How do I create a shared playlist on SoundCloud?

You can share a track or playlist through a message at anytime through the 'Share' button below it's waveform. Go to the Message tab and type in the Profile URL of your recipient. If you are following them, it will auto-fill their name for you.

Does SoundCloud have a playlist?

Playlists are sets or 'albums' that you can create using your own or other people's tracks on SoundCloud. You can view playlists you have liked or created on your Collections page through the playlist tab. Or you can view just the playlists that you have created through the Playlist tab.


2 Answers

Can you try sending the client_secret => 'YOUR_CLIENT_SECRET' as part of the initialize call

like image 135
HGrover Avatar answered Sep 20 '22 16:09

HGrover


It doesn't look like there is such a thing in soundcloud to have a temporary playlist, you will need to delete the playlist on exit....

The best guess would be to see how to format your url to match when someone clicks on the delete button which you can find here: http://help.soundcloud.com/customer/portal/articles/282512-how-do-i-delete-tracks-from-my-account- I don't have an account so I can't test this part.

The key to creating the playlist is having the right track ids. It is possible if your having an issue that the track id doesn't exist and so it doesn't get added to the playlist.

<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
// initialize client with app credentials
SC.initialize({
  client_id: 'MY_CLIENT_ID',
  redirect_uri: 'http://localhost.local/~****/sc/callback.html'
});

// initiate auth popup and create new playlist
SC.connect(function() {
    SC.get('/me', function(me) {
        console.log(me.username);
    });

    var tracks = [12573606].map(function(id) { return { id: id }; });
    SC.post('/playlists', {
        playlist: { title: 'My Playlist', tracks: tracks }
    });
    //As you can see it is a simple array of ids of track
    tracks = [21778201, 22448500, 21928809];
    //To get all playlists remove limit and search each playlist name and grab id
    SC.get('/me/playlists', { limit: 1 }, function(playlist) {
      SC.put(playlist.uri, { playlist: { tracks: tracks } });
    });

    //Then to get all the tracks, please substitute the playlist id for 1234323:
    SC.get('/playlists/1234323', function(playlist) {
      for (var i = 0; i < playlist.tracks.length; i++) {
         console.log(playlist.tracks[i].length);
      }
    });
});
like image 40
msj121 Avatar answered Sep 22 '22 16:09

msj121