我在xcode中保存了一个视频:我该怎么玩?

时间:2011-05-25 21:33:38

标签: iphone objective-c

我已经在使用MediaPlayer框架,但媒体播放器只能通过URL初始化。我的视频已保存在我的项目中,所以我该如何播放?

3 个答案:

答案 0 :(得分:9)

网址也可以是文件路径(file://):

NSURL *movieURL = [[NSBundle mainBundle] URLForResource:@"movie" withExtension:@"mp4"];

答案 1 :(得分:1)

您还可以在UIWebview中播放视频。

CGRect webFrame = CGRectMake(0.0, 0.0, 1, 1);
UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];
[webView setBackgroundColor:[UIColor whiteColor]];
webView.scalesPageToFit =YES;
webView.autoresizingMask =YES;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test123" ofType:@"mp4"]isDirectory:NO]]];
[self.view insertSubview:webView atIndex:0];

答案 2 :(得分:1)

我正在尝试在UIView中播放视频,所以我的第一步是为该视图添加一个类,并使用此代码开始在其中播放电影:

- (IBAction)movie:(id)sender{
    NSBundle *bundle = [NSBundle mainBundle];
        NSString *moviePath = [bundle pathForResource:@"Movie" ofType:@"m4v"];
    NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    [theMovie play];
}