MPMoviePlayerController不播放视频的全长

时间:2013-08-22 05:35:08

标签: iphone ios objective-c mpmovieplayercontroller

我正在使用MPMoviePlayerController打开一个视频文件。视频运行正常。但是假设视频文件是10秒,剩下1秒视频停止。这是它自然的播放方式还是我们应该指定一些东西。以下是使用的代码

NSURL *fileURL = [NSURL URLWithString:location];

self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];

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

self.moviePlayerController.controlStyle = MPMovieControlStyleFullscreen;
self.moviePlayerController.movieSourceType = MPMovieSourceTypeFile;
[self.moviePlayerController prepareToPlay];
[self.moviePlayerController.view setFrame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview:self.moviePlayerController.view];

- (void)moviePlaybackComplete:(NSNotification *)notification {

NSNumber *finishReason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];

if ([finishReason intValue] != MPMovieFinishReasonPlaybackEnded) {
    self.moviePlayerController = [notification object];
    self.moviePlayerController.view.hidden = YES;
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:self.moviePlayerController];

    [self.moviePlayerController.view removeFromSuperview];
    [self.moviePlayerController release];
}

[self dismissViewControllerAnimated:YES completion:nil];

}

0 个答案:

没有答案