【问题标题】:Xcode 5 Play Movie using MPMoviePlayer returns SIGABRTXcode 5 使用 MPMoviePlayer 播放电影返回 SIGABRT
【发布时间】:2014-08-08 02:32:49
【问题描述】:

我一直在尝试通过单击 UIButton 来播放本地视频文件,并且每次单击模拟器中的按钮时都会继续返回 SIGABRT 错误。我试过 m4v 和 mp4 文件。下面是我尝试过但仍返回 SIGABRT 的最新代码集。这组确切的代码似乎适用于 YouTube 上的每个人,但在我运行我的应用程序时不起作用。是的...我确实导入了 MediaPlayer 框架。 Xcode 5.1.1 有什么不同吗?

//  ViewController.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface ViewController : UIViewController

- (IBAction)playButton:(id)sender;

@end


//  ViewController.m
#import "ViewController.h"

@interface ViewController ()
@end
@implementation ViewController

- (IBAction)playButton:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"movie1" ofType:@"m4v"]];

MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

[playerController.moviePlayer play];
playerController = nil;
}

【问题讨论】:

  • 我认为您的笔尖或情节提要有错误,请检查所有连接是否正确(IBOutlets 和 IBActions)。检查fileURLWithPath:也可能返回nil,也可以尝试用fileURLWithString替换它
  • 如果您在控制台中遇到任何特定错误,请使用这些错误更新问题。您使用 playerController = nil;.
  • libc++abi.dylib: 以 NSException (lldb) 类型的未捕获异常终止,这意味着什么吗?
  • 好的,我现在可以在将 fileWithURLPath 更改为 URLWithString 后让视频播放器显示,但它只会继续说永远加载。
  • 我也有它,所以视频播放器会短暂显示然后消失并给出错误“_itemFailedToPlayToEnd: { kind = 1; new = 2; old = 0; }”

标签: ios xcode mpmovieplayercontroller sigabrt


【解决方案1】:

这行得通:

//ViewController.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface ViewController : UIViewController

- (IBAction)playButton;
@property MPMoviePlayerController *mpc;

@end

//ViewController.m
#import "ViewController.h"
@interface ViewController ()

@end

@implementation ViewController
@synthesize mpc;

- (IBAction)playButton
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"videofile" ofType:@"mov"];
NSURL *url = [NSURL fileURLWithPath:bundle];
mpc = [[MPMoviePlayerController alloc] initWithContentURL:url];

[mpc setMovieSourceType:MPMovieSourceTypeFile];

[[self view]addSubview:mpc.view];
[mpc setFullscreen:YES];

[mpc play];
}

@end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    相关资源
    最近更新 更多