【问题标题】:the app crash all the time with a video player使用视频播放器时,应用程序总是崩溃
【发布时间】:2012-08-14 02:00:19
【问题描述】:

我正在尝试将视频代码放入我正在使用情节提要的 Xcode 中,但每次让我崩溃时,这就是错误:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[NSURL initFileURLWithPath:]: nil string parameter” * 首先抛出调用栈:

我将按钮连接到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 large 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];

}

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

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

这是错误:

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

【问题讨论】:

    标签: ios


    【解决方案1】:

    因为你试图通过MPMoviePlayer播放FLV文件。

    这是来自 MPMoviePlayerController 支持格式的苹果 api 文档:

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

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

    【讨论】:

    • 好吧,除了你在 FLV 不兼容 iOS 上完全正确之外——崩溃肯定有不同的原因。原因是给定的字符串是nil
    • 我的文件是 name.mp4 large 480* 360 但它崩溃了这是代码 - (IBAction)playMove; { NSURL *url =[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"go" ofType:@"mp4"]]; MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL:url]; [self presentMoviePlayerViewControllerAnimated:player]; player.movi​​ePlayer.movi​​eSourceType = MPMovieSourceTypeFile; [player.movi​​ePlayer 播放];玩家=无; } 和按钮连接我能做什么?
    • 好的,我需要做的是代码 - (IBAction)playMove; { NSURL url =[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"]]; MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL:url]; player.movi​​ePlayer.movi​​eSourceType = MPMovieSourceTypeFile; [self presentMoviePlayerViewControllerAnimated:player]; [player.movi​​ePlayer 播放];这是由于未捕获的异常'NSInvalidArgumentException'而导致的错误终止应用程序,原因:'** -[NSURL initFileURLWithPath:]: nil string parameter'
    猜你喜欢
    • 1970-01-01
    • 2020-01-26
    • 2017-01-10
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    • 2015-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多