gpt4 book ai didi

ios - 使用视频播放器时应用程序总是崩溃

转载 作者:行者123 更新时间:2023-11-29 04:29:19 25 4
gpt4 key购买 nike

我正在尝试将视频代码放入 Xcode 中,我正在使用 Storyboard ,但每次崩溃时都会出现错误:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[NSURL initFileURLWithPath:]:nil 字符串参数”*第一次抛出调用堆栈:

我将按钮连接到IBAction,但按下按钮后应用程序崩溃了

- (IBAction)playMove;
{
NSString *url = [[NSBundle mainBundle]pathForResource:@"skill" ofType:@"flv"];


MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:url]];
theMovie.view.frame = CGRectMake(64, 100, 200, 150);
[self.view addSubview:theMovie.view];

[theMovie play];
}

我的文件是name.mp4大480* 360,但这就是它崩溃了这是代码

- (IBAction)playMove;
{
NSURL *url =[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"go" ofType:@"mp4"]];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:player];
player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[player.moviePlayer play];

}

按钮连接正常,我该怎么修复它?

我尝试在没有 Storyboard和有 Storyboard的情况下使用,但总是崩溃。

这是错误:

NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** First throw call stack:
(0x1e0a022 0x1348cd6 0x1db2a48 0x1db29b9 0xb9753b 0xb974c5 0x21dc 0x1e0be99 0x25814e 0x2580e6 0x2feade 0x2fefa7 0x2fe266 0x27d3c0 0x27d5e6 0x263d

最佳答案

这是因为您正在尝试通过 MPMoviePlayer 播放 FLV 文件。

这来自 Apple api 文档,了解 MPMoviePlayerController 支持的格式:

支持的格式
此类播放 iOS 支持的任何电影或音频文件。这包括流式内容和固定长度文件。对于电影文件,这通常意味着扩展名为 .mov、.mp4、.mpv 和 .3gp 并使用以下压缩标准之一的文件:

H.264 基线配置文件级别 3.0 视频,30 fps 时高达 640 x 480。 (Baseline 配置文件不支持 B 帧。)MPEG-4 第 2 部分视频(简单配置文件)如果您使用此类来播放音频文件,它将在音频播放时显示带有 QuickTime Logo 的白屏。对于音频文件,此类支持高达 48 kHz 的 AAC-LC 音频和高达 48 kHz 的 MP3(MPEG-1 音频层 3)立体声音频。

关于ios - 使用视频播放器时应用程序总是崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11924591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com