Search code examples
iosobjective-cxcoderdio

Can't get Rdio iOS SDK playback to work


I'm messing around with Rdio's iOS SDK. I've set up everything correctly in "Getting Started" outlined here (http://www.rdio.com/developers/docs/libraries/ios/). The track key in the app delegate works and plays after I launch the app.

Now I'm trying to get a simple UIButton click to play a track, and I can't for the life of me get it to work.

I have this in ViewController.h

#import <UIKit/UIKit.h>
#import <Rdio/Rdio.h>

@interface ViewController : UIViewController <RdioDelegate, RDPlayerDelegate>
@property (readonly) Rdio *rdio;

@end

And in ViewController.m

- (IBAction)playButton:(UIButton *)sender
{
    [self.rdio preparePlayerWithDelegate:nil];
    NSArray *sources = [NSArray arrayWithObjects:@"t1", @"p1", @"a1", nil];
    [self.rdio.player playSources:sources];

}

I really appreciate the help!


Solution

  • I resolved my issue. My issue was I wasn't calling the initializer initWithConsumerKey... that I had in my App Delegate. I had also failed to set it as a delegate properly.

    So my App Delegate looks like this:

    #import "AppDelegate.h"
    
    static AppDelegate *launchedDelegate;
    
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    + (Rdio *)rdioInstance
    {
        return launchedDelegate.rdio;
    }
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        launchedDelegate = self;
    
        _rdio = [[Rdio alloc] initWithConsumerKey:@"removed" andSecret:@"removed" delegate:nil];
        return YES;
    }
    

    and in ViewController.m:

    - (IBAction)listenButton:(UIButton *)sender
    {
        _rdio = [AppDelegate rdioInstance];
        [self.rdio preparePlayerWithDelegate:nil];
        [self.rdio.player playSource:@"p12691138"];
    
    }
    

    Feeling silly that I didn't get that at first! Leaving it up here in case it helps anybody.