繁体   English   中英

iOS应用:从mainBundle播放mp4文件时崩溃

[英]iOS App: playing mp4 file from mainBundle crashes

我正在尝试从我的应用程序内部播放test.mp4,但由于以下错误而崩溃:

2013-06-28 15:02:40.931 framing[9617:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** First throw call stack:
(0x1a5f012 0x176ce7e 0x1a5edeb 0x11839b1 0x118393b 0x28c2 0x1780705 0x6b42c0 0x6b4258 0x775021 0x77557f 0x7746e8 0x6e3cef 0x6e3f02 0x6c1d4a 0x6b3698 0x2ac1df9 0x2ac1ad0 0x19d4bf5 0x19d4962 0x1a05bb6 0x1a04f44 0x1a04e1b 0x2ac07e3 0x2ac0668 0x6b0ffc 0x223d 0x2165)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

以下是代码:

#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>

@implementation ViewController
@synthesize moviePlayer,movieScreen,viewVideoTitleBg;

-(IBAction)playTheMovie {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp4"];
    moviePlayer = [[MPMoviePlayerController
                    alloc]initWithContentURL:[NSURL fileURLWithPath:path]];
    //[self presentMoviePlayerViewControllerAnimated:moviePlayer];
    moviePlayer.controlStyle = MPMovieControlStyleDefault;
    moviePlayer.shouldAutoplay = YES;
    moviePlayer.view.frame = CGRectMake(64,192,895,415);
    [self.view addSubview:moviePlayer.view];
    //[moviePlayer setFullscreen:NO animated:YES];
    [moviePlayer play];
}

我也安装了框架。

我的代码有什么问题?

我最近遇到了这个问题。 我的解决方法是从捆绑软件中删除视频文件,然后再次将其拖放。

清理并构建,然后再次运行。

但是例如:您应该检查视频文件名称和代码中使用的名称的拼写和大写。

尝试使用[NSURL URLWithString:path]; 而不是[NSURL fileURLWithPath:path];

检查一下

[[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp4"]

返回零。 如果返回nil,则需要将mp4文件添加到xcode项目中,并选择SELECT> ADD TO TARGET <复选框。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM