我正在尝试从项目目录加载视频,任何人都可以建议,我到底错过了什么。
NSURL *myURL =[[NSBundle mainBundle] URLForResource:@"US_Very_High_Dive_Boudia_US_44_x264"
withExtension:@"mp4"];
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player prepareToPlay];
[player shouldAutoplay];
[player allowsAirPlay];
[self.view addSubview:player.view];
[player setFullscreen:YES animated:YES];
player.controlStyle=MPMovieControlStyleEmbedded;
答案 0 :(得分:2)
试试此代码
在.h文件中添加以下内容
@property (nonatomic, strong) MPMoviePlayerController *controller;
在.m文件中
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"buyTutorial" ofType:@"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController prepareToPlay];
[moviePlayerController play];
[self setController:moviePlayerController];
}
答案 1 :(得分:0)
好像你没有正确设置网址 - 试试这个:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"filename" ofType:@"mp4"]];