首页 > 移动平台 > 详细

iOS之视频播放MPMoviePlayerViewController

时间:2015-07-14 16:57:54      阅读:218      评论:0      收藏:0      [点我收藏+]

需要导入的框架

#import <MediaPlayer/MediaPlayer.h>

MediaPlayer.framework

 

MPMoviePlayerViewController:

打开网络视频:

-(void)openmovie

{

    MPMoviePlayerViewController *movie = [[MPMoviePlayerViewControlleralloc]initWithContentURL:[NSURLURLWithString:@"视频网络地址"]];

    

    [movie.moviePlayer prepareToPlay];

    [self presentMoviePlayerViewControllerAnimated:movie];

    [movie.moviePlayersetControlStyle:MPMovieControlStyleFullscreen];

    

    [movie.viewsetBackgroundColor:[UIColorclearColor]];

    

    [movie.view setFrame:self.view.bounds];

    [[NSNotificationCenterdefaultCenter]addObserver:self

     

                                            selector:@selector(movieFinishedCallback:)

     

                                                name:MPMoviePlayerPlaybackDidFinishNotification

     

                                               object:movie.moviePlayer];

 

}

-(void)movieFinishedCallback:(NSNotification*)notify{

    

    // 视频播放完或者在presentMoviePlayerViewControllerAnimated下的Done按钮被点击响应的通知。

    

    MPMoviePlayerController* theMovie = [notifyobject];

    

    [[NSNotificationCenterdefaultCenter]removeObserver:self

     

                                                   name:MPMoviePlayerPlaybackDidFinishNotification

     

                                                  object:theMovie];

    

    [selfdismissMoviePlayerViewControllerAnimated];

    

}

打开本地视频:

-(void)openmovie

{

  

   NSString *url = [[NSBundlemainBundle]pathForResource:@"IMG_0322"ofType:@"mp4"];

    MPMoviePlayerViewController *playerViewController  = [[MPMoviePlayerViewControlleralloc]initWithContentURL:[NSURLfileURLWithPath:url]];

    [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(movieFinishedCallback:)

                                                name:MPMoviePlayerPlaybackDidFinishNotification

                                              object:[playerViewControllermoviePlayer]];

 

    [self.view addSubview:playerViewController.view];

    

 

    MPMoviePlayerController *player = [playerViewControllermoviePlayer];

    [playerplay];

    

}

- (void) movieFinishedCallback:(NSNotification*) aNotification {

   MPMoviePlayerController *player = [aNotificationobject];

    [[NSNotificationCenterdefaultCenter]removeObserver:selfname:MPMoviePlayerPlaybackDidFinishNotificationobject:player];

    [playerstop];

    [player.viewremoveFromSuperview];

   

}

 

iOS之视频播放MPMoviePlayerViewController

原文:http://www.cnblogs.com/Sucri/p/4645493.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!