views:

330

answers:

1

I try to play a video on the server with this code. I have a error.

//Play the video from server
    - (IBAction)playVideo:(id)sender;
    {
        NNSURL *url = [[NSURL alloc]initWithString: aVideo.urlVideo];
NSLog(@"URLVIDEO %@", url);
MPMoviePlayerController *VideoPlayer = [[MPMoviePlayerController alloc]initWithContentURL: url];
[VideoPlayer play];      
    }

//Console

URLVIDEO http://147.83.74.180/videos/low/ElTemps-index.m3u8
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Content URL must not be nil.'

aVideo.urlVideo is defined on the Video class and it gets a value when I parse an xml file

//Video.h
NSString urlVideo;

//XMLParser.m
    [aVideo setValue:currentElementValue forKey:elementName]; //here i add the string

If I do this I can play the video:

NSString *videoURL = @"http://147.83.74.180/videos/low/ElTemps-index.m3u8";
    MPMoviePlayerController *VideoPlayer = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:videoURL]];
A: 

aVideo.urlVideo isn't a valid URL string. It is the NSURL that is nil.

Paul Lynch
How can i solve this?
skiria
If we don't know what the string is, we can't comment on it.
Paul Lynch
I paste more code. I don't know if it's what you tell me...
skiria
You need to check why contentURL is nil. It could be because the string you pass is invalid - you should now check if it was released, and try logging the NSURL separately.
Paul Lynch
I don't know why the string is invalid (see my test on the question). And I also try to log the NSULR separately and the problem persist.
skiria
I did see the NSLog; but that doesn't tell you if the string was autoreleased or not, which could cause the problem. See my previous comment.
Paul Lynch
In Video.m I release urlVideo and I also release aVideo on dealloc method, do you refer on this? But I don't know how can i check it....
skiria
I use this NSURL *url = [URLWithString: acVideo.urlVideo]; NSLog(@"URL %@", url); NSLog(@"URLVIDEO %@", acVideo.urlVideo); acVideo.urlVideo has the correct value, but url is null. What's wrong?
skiria
Ideally we should see how you are allocating and releasing urlVideo (and aVideo), that is the most likely source of your problem.
Paul Lynch
Solved. The code is ok. The problem was that the string that I try to convert to NSurl has a space before the first letter. thanks for your help!
skiria