Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C NSURL URLWithString appears to fail when using variable

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?

like image 675
Mark D. Avatar asked Sep 14 '26 22:09

Mark D.


1 Answers

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

aArchiveItem.streamURL=[aArchiveItem.streamURL stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
like image 200
YNK Avatar answered Sep 16 '26 11:09

YNK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!