我很难理解为什么这不起作用:/每次我运行项目时,应用程序都会崩溃,给我一个 'NSInvalidArgumentException',原因:' * -[NSURL initFileURLWithPath:]: nil string parameter'
我遵循了一个教程(我对此很陌生),它对他有用,代码完全一样。任何人都可以解释发生了什么吗?
.h 文件
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <QuartzCore/QuartzCore.h>
@interface FirstViewController : UIViewController {
MPMoviePlayerViewController *playerController;
}
-(IBAction)playVideo;
@end
.m 文件
#import "FirstViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
{
MPMoviePlayerController *mpc;
}
- (IBAction)playButton:(id)sender {
NSString *stringPath = [[NSBundle mainBundle]pathForResource:@"intro" ofType:@"MP4"];
NSURL *url = [NSURL fileURLWithPath:stringPath];
if(url != nil){
mpc = [[MPMoviePlayerController alloc]initWithContentURL:url];
[mpc setMovieSourceType:MPMovieSourceTypeFile];
[[self view]addSubview:mpc.view];
[mpc setFullscreen:YES];
[mpc play];
}
else{
NSLog(@"URL not found");
}
}
@end