//
// PlayerViewController.h
// MPMoviePlayerDemo
//
//
#import
#import
@interface PlayerViewController : MPMoviePlayerViewController
@end
//
// PlayerViewController.m
// MPMoviePlayerDemo
//
#import "PlayerViewController.h"
@interface PlayerViewController ()
@end
@implementation PlayerViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//---------------6.0之后使用一下两个方法控制横屏、竖屏--------------------------
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}
//6.0之前用于控制横、竖
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
return YES;
}
return NO;
}
@end
//
// MainViewController.h
// MPMoviePlayerDemo
//
#import
@interface MainViewController : UIViewController
- (IBAction)playAction:(id)sender;
@end
//
// MainViewController.m
// MPMoviePlayerDemo
//
#import "MainViewController.h"
#import
#import "PlayerViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(playDidChangeNotification:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
}
return self;
}
- (void)playDidChangeNotification:(NSNotification *)notification {
MPMoviePlayerController *moviePlayer = notification.object;
MPMoviePlaybackState playState = moviePlayer.playbackState;
if (playState == MPMoviePlaybackStateStopped) {
NSLog(@"停止");
} else if(playState == MPMoviePlaybackStatePlaying) {
NSLog(@"播放");
} else if(playState == MPMoviePlaybackStatePaused) {
NSLog(@"暂停");
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// NSString *urlstring = @"http://tv.flytv.com.cn/seg/17.m3u8";
// NSURL *url = [NSURL URLWithString:urlstring];
//
// MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// moviePlayer.view.frame = CGRectMake(0, 0, 320, 200);
// moviePlayer.backgroundView.backgroundColor = [UIColor orangeColor];
// [self.view addSubview:moviePlayer.view];
//
// [moviePlayer play];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)playAction:(id)sender {
NSString *urlstring = @"http://tv.flytv.com.cn/seg/17.m3u8";
NSURL *url = [NSURL URLWithString:urlstring];
MPMoviePlayerViewController *playerViewController = [[PlayerViewController alloc]initWithContentURL:url];
// [self presentViewController:playerViewController animated:YES completion:NULL];
[self presentMoviePlayerViewControllerAnimated:playerViewController];
}
@end