118 系统视频播放

来源:互联网 发布:c语言的缺陷与陷阱pdf 编辑:程序博客网 时间:2024/04/30 12:29

1.AVPlayer播放本地和远程

- (void)avPlayer{    //NSURL *url = [[NSBundle mainBundle] URLForResource:@"minion_01.mp4" withExtension:nil];    NSURL *url = [NSURL URLWithString:@"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];    // 创建播放器    AVPlayer *player = [AVPlayer playerWithURL:url];    [player play];    // 创建播放器图层    AVPlayerLayer *layer = [AVPlayerLayer layer];    layer.player = player;    layer.frame = CGRectMake(10, 0, 300, 200);    // 添加图层到控制器的view    [self.view.layer addSublayer:layer];    self.player = player;}

2.MPMoviePlayerController视频播放(无界面)

- (void)moviewPlayerController{    // 创建播放器对象(属性直接赋值,不是属性会黑屏)    self.mpc = [[MPMoviePlayerController alloc] init];    // 设置URL    //self.mpc.contentURL = [[NSBundle mainBundle] URLForResource:@"minion_01.mp4" withExtension:nil];      self.mpc.contentURL = [NSURL URLWithString:@"http://streams.videolan.org/streams/mp4/Mr_MrsSmith-h264_aac.mp4"];    // 添加播放器界面到控制器的view上面    self.mpc.view.frame = CGRectMake(10, 50, 300, 200);    [self.view addSubview:self.mpc.view];    [self.mpc play];    // 隐藏自动自带的控制面板    self.mpc.controlStyle = MPMovieControlStyleNone;    // 监听播放器    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDidFinish) name:MPMoviePlayerPlaybackDidFinishNotification object:self.mpc];    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieStateDidChange) name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.mpc];}

3.MPMoviePlayerViewController(有界面)

- (void)moviewPlayerViewController{    //NSURL *url = [[NSBundle mainBundle] URLForResource:@"minion_01.mp4" withExtension:nil];    NSURL *url = [NSURL URLWithString:@"http://y1.eoews.com/assets/ringtones/2012/5/18/34045/hi4dwfmrxm2citwjcc5841z3tiqaeeoczhbtfoex.mp3"];    MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];    [self presentMoviePlayerViewControllerAnimated:mpvc];}
0 0
原创粉丝点击