我很难理解为什么这不起作用:/每次运行项目时,应用程序崩溃都会给我一个'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
Run Code Online (Sandbox Code Playgroud)
.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
Run Code Online (Sandbox Code Playgroud)