码迷,mamicode.com
首页 > 其他好文 > 详细

MPMoviePlayerController播放视频

时间:2016-08-16 17:32:12      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:

  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];

}

 

MPMoviePlayerController播放视频

标签:

原文地址:http://www.cnblogs.com/YuFly-lyx/p/5777157.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!