Jor*_*rle 8 iphone video ios ios6
我很难理解为什么这不起作用:/每次运行项目时,应用程序崩溃都会给我一个'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)
Kur*_*vis 34
所有这一切中唯一重要的部分是:
NSString *stringPath = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"MP4"];
NSURL *url = [NSURL fileURLWithPath:stringPath];
Run Code Online (Sandbox Code Playgroud)
我假设在第二行内引发了异常.这意味着stringPath
nil,如果文件intro.MP4
实际上不在您的应用程序包中,则会发生这种情况.
检查:
该文件存在于您的源代码副本中
你的Xcode项目有一个对该文件的引用(如果它是红色,则表示文件实际上不存在)
在Xcode的目标中,查看"Build Phases"并显示"Copy Bundle Resources"构建阶段.该文件应该存在.如果不是,请按+按钮并选择它.
小智 6
库尔特的回答特别适用于我
"在Xcode的目标中,查看"Build Phases"并显示"Copy Bundle Resources"构建阶段.该文件应该存在.如果不存在,请按+按钮并选择它."
我的电影文件丢失了.它一定是在那之前因为它正在工作然后它就停止了.
我会对Kurt的帖子发表评论,但不知道如何.我做了"投票".
归档时间: |
|
查看次数: |
16978 次 |
最近记录: |