views:

619

answers:

2

So this is my first posting on StackOverflow, so excuse me if my request is not well formed.

I am attempting to load a variable with type NSString into an NSURL with the following line:

audioPlayer = [[AudioPlayer alloc] initPlayerWithURL:[NSURL URLWithString:aArchiveItem.streamURL] delegate:self];

And in AudioPlayer implementation I am using:

-(id)initPlayerWithURL:(NSURL *)url delegate:(id<AudioPlayerDelegate>) aDelegate {
    self = [super init];

    delegate = aDelegate;

    queue = [[AudioQueue alloc] initQueueWithDelegate:self];

    fileStream = [[AudioFileStream alloc] initFileStreamWithDelegate:self];
    [fileStream open];

    request = [[AudioRequest alloc] initRequestWithURL:url delegate:self];

    return self;
}

When I hardcode a URL string(e.g. URLWithString:@"http://www.example.com") the call to the audioPlayer work flawlessly, but when attempting to populate it with the value of aArchiveItem.streamURL it fails...

What am I doing wrong here?

+3  A: 

Use the debugger. Break on the first line you listed and evaluate what "aArchiveItem.streamURL" actually is at the time. Is it actually a well-formed URL string?

Also, "it fails" is not enough information. In what way, exactly? I'm guessing the URL you're trying to create with aArchiveItem.streamURL is nil (because the string is not valid) and things expecting a URL are griping, but that's only a guess.

Joshua Nozzi
When stepping through the code with breakpoint placed as suggested it shows the value of aArchiveItem.streamURL being \n\t\thttp://www.example.com/example.mp3For clarification on "it fails" I mean it fails to download the requested file... Upon setting a breakpoint at: -(id)initPlayerWithURL:(NSURL *)url delegate:(id<AudioPlayerDelegate>) aDelegate {It shows the value of url as nil
Mark D.
If your URL really does start with \n\t\t, then it's not a valid URL string. Or have I misunderstood?
Joshua Nozzi
+3  A: 

probably your url has white spaces try to do the following before the using the url:

aArchiveItem.streamURL=[aArchiveItem.streamURL stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
YNK
Adding this line just previous to the call to audioPlayer worked flawlessly, THANK YOU THANK YOU THANK YOU... I've been scratching my head on this for days!
Mark D.
you are welcome :)
YNK