0

我正在尝试在设备上播放视频。视频就是这个 视频

和我的代码:

  NSString *urlStr = @"http://easyhtml5video.com/images/happyfit2.mp4";
NSURL *url = [NSURL fileURLWithPath:urlStr];
  moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(0, 0, 320, 400);  
[moviePlayer play];

当我启动应用程序时,会看到一个电影屏幕,但没有播放电影。你能帮我看看错在哪里吗?

4

2 回答 2

1

尝试使用 NSURL *url = [NSURL URLWithPath:urlStr];

而不是 NSURL *url = [NSURL fileURLWithPath:urlStr]; 它是一个网页网址而不是文件网址。

于 2013-01-02T08:21:10.207 回答
0

检查此视频以供参考。这对我有用 -

- (IBAction)playMovie:(id)sender
{
    NSString *filepath   =   @"http://easyhtml5video.com/images/happyfit2.mp4";
    NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];
    MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:)
                                                               name:MPMoviePlayerPlaybackDidFinishNotification
                                                             object:moviePlayerController];

    [self.view addSubview:moviePlayerController.view];
    moviePlayerController.fullscreen = YES;
    [moviePlayerController play];
}

- (void)moviePlaybackComplete:(NSNotification *)notification
{
    MPMoviePlayerController *moviePlayerController = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                         name:MPMoviePlayerPlaybackDidFinishNotification
                                                                                object:moviePlayerController];

    [moviePlayerController.view removeFromSuperview];
    [moviePlayerController release];
}
于 2012-05-31T10:47:25.323 回答