在iPhone应用程序中集成视频

时间:2011-10-18 08:09:54

标签: iphone mpmovieplayercontroller

我必须将视频集成到我的iphone应用程序中。与网上所有代码的区别在于我必须显示视频并向用户提供播放它的机会。不要自动播放

这就是我所做的:

- (void) play
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"video1" ofType:@"mp4"];
    NSURL *fileUrl1 = [NSURL fileURLWithPath:path];
    videoPlayer1 = [[MPMoviePlayerController alloc] initWithContentURL:fileUrl1];
    [videoPlayer1 setControlStyle:MPMovieControlStyleNone];
    [[videoPlayer1 view] setFrame:[self.view bounds]];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

    //[videoPlayer1 play];
    [self.view addSubview:[videoPlayer1 view]];    
}
- (void) moviePlayBackDidFinish:(NSNotification*)_notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:nil];

    [videoPlayer1.view removeFromSuperview];
    [videoPlayer1 stop];
    [videoPlayer1 release];
    videoPlayer1 = nil;
}

但是屏幕只是变黑了,没有其他任何显示。

除非我[videoPlayer1 play]没有任何反应。但我不想自动播放视频......必须由用户播放。 那么,我应该如何表现视频(!而不是黑屏)并在用户希望时播放?谢谢

1 个答案:

答案 0 :(得分:0)

你出错了,这里是

更改此

[videoPlayer1 setControlStyle:MPMovieControlStyleNone];

[videoPlayer1 setControlStyle:MPMovieControlStyleDefault];

您正在使用您的那条线隐藏控件。

干杯!!!

相关问题