单击主页按钮后视频无法正常工作

时间:2013-06-24 09:38:16

标签: iphone objective-c mpmovieplayercontroller

我创建了一个包含MPMoviePlayer的视图,可以在屏幕上播放视频。当我第一次打开它并且当我去另一个视图然后回来时,它工作正常 当我通过单击主页按钮离开应用程序并返回应用程序时,视频似乎不起作用。它是一种让它运行的方式吗?

这是代码[我把它放在viewDidLoad]中:

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                         pathForResource:@"video" ofType:@"mp4"]];

    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

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

    moviePlayer.controlStyle = MPMovieControlStyleNone;
    moviePlayer.repeatMode = MPMovieRepeatModeOne;
    moviePlayer.shouldAutoplay = YES;
    moviePlayer.scalingMode = MPMovieScalingModeFill;
    [moviePlayer.view setFrame:CGRectMake(0,0,480,320)];

    [moviePlayer prepareToPlay];
    [self.view addSubview:moviePlayer.view];

0 个答案:

没有答案