3

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?

1
  • Have you print out the string before the call to check if the string is correct ? i.e. NSLog(@"<%@>", aArchiveItem.streamUR); Commented Dec 1, 2009 at 16:13

2 Answers 2

6

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

aArchiveItem.streamURL=[aArchiveItem.streamURL stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
Sign up to request clarification or add additional context in comments.

1 Comment

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!
4

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.

2 Comments

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.mp3 For 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
If your URL really does start with \n\t\t, then it's not a valid URL string. Or have I misunderstood?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.