0

我创建了一个包含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];
4

0 回答 0