标签:
MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:ddi.videoFileUrl];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name: MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerWillExitFullscreenNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
moviePlayer.movieSourceType=MPMovieSourceTypeFile;//这句重要,没有这句视频一片漆黑,无法播放(本地视频)MPMovieSourceTypeStreaming(网路视频)
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
#pragma mark - NSNotificationCenter
-(void)moviePlayBackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerWillExitFullscreenNotification object:moviePlayer];
// If the moviePlayer.view was added to the view, it needs to be removed
if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
[moviePlayer.view removeFromSuperview];
}
// [moviePlayer release];
}
标签:
原文地址:http://www.cnblogs.com/YuFly-lyx/p/5777157.html