7.iOS 视频播放2MPMoviePlayerViewController

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
//添加 MediaPlayer.framework 库
@interface MainViewController : UIViewController
- (IBAction)playBtn:(id)sender;

@end
#import "MainViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

-(void)MoviePlayerChange:(NSNotification *)notification
{
    MPMoviePlayerController *moviePlayer=notification.object;
    MPMoviePlaybackState playState=moviePlayer.playbackState;
    if (playState==MPMoviePlaybackStatePaused) {
        NSLog(@"暂停");
    }
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)playBtn:(id)sender {
    NSString *path=[[NSBundle mainBundle]pathForResource:@"少女时代oh超清 高清" ofType:@"mp4"];
    NSURL *url=[NSURL fileURLWithPath:path];
    MPMoviePlayerViewController *playerController=[[MPMoviePlayerViewController alloc]initWithContentURL:url];
    //通过模态视图弹出
//    [self presentViewController:playerController animated:YES completion:^{
//        NSLog(@"模态视图");
//    }];
    
    //或
    [self presentMoviePlayerViewControllerAnimated:playerController];
}
@end


你可能感兴趣的:(7.iOS 视频播放2MPMoviePlayerViewController)