如何在MPMoviePlayer控制器中播放.mp4视频

时间:2015-03-30 07:42:55

标签: ios objective-c iphone

请告诉我如何在MPMoviePlayerController中播放.mp4格式的视频播放

    NSString *urlStr=[[NSBundle mainBundle]pathForResource:@"Tour.mp4" ofType:nil];
    NSURL *url = [NSURL fileURLWithPath:urlStr];
    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [self.view addSubview:moviePlayer.view];
    moviePlayer.view.frame = CGRectMake(0,154,720,428);
    [moviePlayer play];

1 个答案:

答案 0 :(得分:0)

添加MediaPlayer框架

将其导入您的文件

#import <MediaPlayer/MediaPlayer.h>

创建MPMoviePlayerController的对象

MPMoviePlayerController * moviePlayer;

write this code where you wants to play video    

NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"test.mp4" ofType:nil];  
NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];   
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];  
[self.view addSubview:moviePlayer.view];      
moviePlayer.fullscreen = YES;   
[moviePlayer play];

尝试以上代码......