1

我正在尝试从项目目录加载视频,任何人都可以建议,我到底缺少什么。

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;
4

2 回答 2

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];
            }
于 2013-02-21T07:28:11.063 回答
0

好像您没有正确设置 URL - 试试这个:

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"filename" ofType:@"mp4"]];
于 2013-02-21T07:32:07.517 回答