我一直在尝试通过单击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;
}
答案 0 :(得分:0)
这有效:
//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