Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing a SoundCloud file in IOS app

Tags:

ios

soundcloud

Using the quick start guide provided would like to play a SoundCloud track within IOS app.

The code provided to play the stream is here:

SCAccount *account = [SCSoundCloud account];

    [SCRequest performMethod:SCRequestMethodGET
                  onResource:[NSURL URLWithString:audioFile]
             usingParameters:nil
                 withAccount:account
      sendingProgressHandler:nil
             responseHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                 NSError *playerError;
                 audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:&playerError];
                 audioPlayer.numberOfLoops = 0;

                 [audioPlayer prepareToPlay];
                 [audioPlayer play];
             }];

Problem: is there a method to play a SoundCloud file without logging in to your SoundCloud account first? We hope all users consider using SoundCloud - however for usability if would be useful if new users could listen to a number of tracks before.

like image 336
Magnus Avatar asked Mar 21 '13 00:03

Magnus


People also ask

Can I download SoundCloud songs to my iPhone?

Saving content on mobile devicesIt is not possible to download a track from a mobile device. However, users with a SoundCloud Go or Go+ subscription can save content for offline listening on a mobile device.

How do you play SoundCloud on Apple?

In order to use SoundCloud with Android Auto, please make sure that you have downloaded the SoundCloud app and are logged in. All you have to do is select SoundCloud from the list of media services in your Library and choose a track to play.

Can I use SoundCloud as a music player?

Users can upload their own music/demos (or any shareable track) to SoundCloud, and then embed a SoundCloud music player on their sites. SoundCloud supports the uploading of AIFF, WAVE, FLAC, OGG, MP2, MP3, AAC, AMR, and WMA files.

How do you download music from SoundCloud to your phone?

Because beginning today, you can upload to SoundCloud directly from your phone. Within the SoundCloud app, tap the upward-pointing arrow on the top right of your home screen. Select any audio file from your phone (upload lossless HD files like FLAC, WAV, ALAC or AIFF for best audio quality).


1 Answers

For public access with the IOS Soundcloud SDK you will need to add the Soundcloud clientID as a parameter to your request string:

NSString *urlString = [NSString stringWithFormat:@"%@?client_id=%@", publicTrackUrlString, yourSCClientID];
[SCRequest performMethod: SCRequestMethodGET 
              onResource: [NSURL URLWithString:urlString]
         usingParameters: nil 
             withAccount: nil
  sendingProgressHandler: nil 
         responseHandler:^(NSURLResponse *response, NSData *data, NSError *error){
                      // 
         }];

Then it will work for public tracks when the withAccount: parameter is nil.

More elegantly, you can as well pack the "client_id" in a dictionary and use it with usingParameters:

NSDictionary *params = @{@"client_id": yourSCClientID} ;

like image 65
sn-gerzonic Avatar answered Oct 25 '22 12:10

sn-gerzonic