简体   繁体   中英

Playing video on IOS

I have downloaded the source files from

http://mobile.tutsplus.com/tutorials/iphone/mediaplayer-framework_mpmovieplayercontroller_ios4/

and the app works perfectly, but when I try to swap out my own video by changing the following code:

pathForResource:@"big-buck-bunny-clip" ofType:@"m4v"

to

pathForResource:@"example" ofType:@"mp4"

the app crashes when I try to play the video and I receive a message in the output saying:

"2012-09-13 20:32:59.106 BigBuckBunny[1081:11f03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[NSURL initFileURLWithPath:]: nil string parameter' * * First throw call stack: (0x1722022 0x10f6cd6 0x16caa48 0x16ca9b9 0x4e53b 0x4e4c5 0x2da4 0x1723e99 0x36d14e 0x36d0e6 0x413ade 0x413fa7 0x413266 0x3923c0 0x3925e6 0x378dc4 0x36c634 0x1e1aef5 0x16f6195 0x165aff2 0x16598da 0x1658d84 0x1658c9b 0x1e197d8 0x1e1988a 0x36a626 0x297d 0x28f5) terminate called throwing an exception(lldb) "

I have my new video file inside the folder with the original big-buck-bunny-clip.m4v file, and I put it in the project. What am I doing wrong and how do I fix this?

通过转到Xcode中的文件并选中“目标成员身份”下BigBuckBunny旁边的框,我设法播放了自己的视频

Check file exits and filepath you r passing is nil:

 NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"example" ofType:@"mp4"];  
 if([[NSFileManager defaultManager] fileExitsAtPath:filepath])
 {
   NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];   
   MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];  
   [self.view addSubview:moviePlayerController.view];  
   moviePlayerController.fullscreen = YES;  
   [moviePlayerController play];    
 }
 else
 {
    NSLog(@"File not exists");
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM