提问人:user1114881 提问时间:10/29/2023 最后编辑:Willekeuser1114881 更新时间:10/30/2023 访问量:40
为什么应用程序包中电影文件的路径为零?
Why is path to movie file in app bundle nil?
问:
当按下按钮时,我正在尝试在我的应用程序中播放本地电影。但是,当我按下按钮时,出现以下错误,应用程序崩溃。
“NSInvalidArgumentException”,原因:“*** -[NSURL initFileURLWithPath:]:nil 字符串参数”
这是我用来播放电影的代码。
NSString *path=[[NSBundle mainBundle]pathForResource:@"koi swimming" ofType:@"m4v"];
NSURL *url = [NSURL fileURLWithPath:path];
AVPlayer *player = [AVPlayer playerWithURL:url];
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.view.frame = self.view.bounds;
[self.view addSubview:controller.view];
[controller.player play];
并且我正在附加我的捆绑文件结构的图像。
有人可以帮忙玩这个吗?
展开的图像文件。
答:
0赞
Mojtaba Hosseini
10/30/2023
#1
您尝试查找的文件()似乎没有添加到目标(在此处)。koi swimming.m4v
Bundle
mainBundle
捆绑包是应用的运行时资源,它与构建时资源不同。
因此,请确保在添加运行时所需的文件时将其添加到所需的目标:
此外,您可以从文件检查器中添加/删除目标中的任何文件,例如:
评论