/*
通过MPMoviePlayerController或者MPMoviewPlayerViewController类(视图控制器)
来播放视频(含流媒体视频播放)
引入“MediaPalyer.franework”
MPMoviePlayerController播放器可以任意修改比方页面尺寸
MPMoviewPlayerViewController特殊视图控制器,包含一个播放器MPMoviePlayerController
*/
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface MianViewController : UIViewController
#import "MianViewController.h"
@interface MianViewController ()
@end
@implementation MianViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
//添加通知监控 MoviePlayer 的变化
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerFinsh:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
}
return self;
}
-(void)MPMoviePlayerFinsh:(NSNotification *)notification
{
// id obj=notification.object;
MPMoviePlayerController *moviePlayer=notification.object;
//播放状态
MPMoviePlaybackState playstate=moviePlayer.playbackState;
if (playstate==MPMoviePlaybackStateSeekingForward) {
NSLog(@"向前");
}
else if(playstate==MPMoviePlaybackStatePaused)
{
NSLog(@"暂停");
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//本地播放
NSString *path=[[NSBundle mainBundle]pathForResource:@"少女时代oh超清 高清" ofType:@"mp4"];
// NSURL *url=[[NSURL alloc]initWithString:@"http://baidu.iqiyi.com/kan/Q9Nm?fr=v.baidu.com/"];
NSURL *url=[NSURL fileURLWithPath:path];
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc]initWithContentURL:url];
moviePlayer.view.frame=CGRectMake(10, 20, 300, 300);
moviePlayer.backgroundView.backgroundColor=[UIColor greenColor];
[self.view addSubview:moviePlayer.view];
/*MPMoviePlaybackState 视频类相关通知
//视频播放结束的通知
MPMoviePlayerPlaybackDidFinishNotification
// Posted when the scaling mode changes.
MPMoviePlayerScalingModeDidChangeNotification
*/
[moviePlayer prepareToPlay];
[moviePlayer play];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end