0

我正在尝试将视频添加到按钮单击(本机视频)中,我的代码完美无缺,它可以编译并运行正常,但是当我单击该按钮时,这意味着本机播放视频......它给了我一个“线程 1 : 信号 SIGBART" ??? 请问我该如何解决?

我已经按照我应该做的一切,将视频导入到支持文件中,并确保在 .m 中将其命名为与其文件名相同的名称。

尝试添加断点异常但不起作用

这是.h中的代码

@interface ViewController5 : UIViewController {

}

-(IBAction)play;

@end

这是.m中的代码

@implementation ViewController5

-(IBAction)play {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:@"test video" ofType:@"mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
                                                 initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
playercontroller = nil;
}

@end

这是我得到的“绿色”高亮信号

int main(int argc, char *argv[])
{
@autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
4

1 回答 1

0

如果您使用 ARC,则应保留对MPMoviePlayerViewController实例的引用,以便在方法返回时不会释放它play,并且不要将其设置为nil.

// ViewController5.h
@interface ViewController5 : UIViewController {
    MPMoviePlayerViewController *playercontroller;
}
- (IBAction)play;
@end

// ViewController5.m
@implementation ViewController5
- (IBAction)play {
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test video" ofType:@"mp4"]];
    playercontroller = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    [self presentMoviePlayerViewControllerAnimated:playercontroller];
    playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    [playercontroller.moviePlayer play];
}
@end
于 2013-07-13T20:48:14.453 回答