iOS简单视频播放代码

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

     1.导入库文件MediaPlayer.framework

     2.#import<MediaPlayer/MediaPlayer.h>

        // 本地文件  
        NSURL *url = [[NSBundle mainBundle] URLForResource:@"xxxxxxxxxxxxxxx" withExtension:@"mov"];  
        // 沙盒中的网络路径 (注意这两种方式的区别)  
        NSURL *videoUrl = [NSURL fileURLWithPath:..................]];  
      
        /** 
         *  与音频不一样,这个,既可以播放本地视频,也能播放网络资源 
         */  
        self.moviePlayVC = [[MPMoviePlayerViewController alloc] initWithContentURL:url];  
        self.moviePlayVC.view.frame = CGRectMake(0, 64, 320, 250);  
        //  推出视频页面的时候不让自动播放  
        self.moviePlayVC.moviePlayer.shouldAutoplay = NO;  
          
        //  播放器样式,自行选择  
        self.moviePlayVC.moviePlayer.controlStyle = MPMovieControlStyleNone;  
          
        [self.view addSubview:self.moviePlayVC.view];  
          
        //  播放器的控制,有点不同,它不是通过协议来实现的,而是通过通知的形式  
        /** 
         *  MPMoviePlayerWillEnterFullscreenNotification 
         *  MPMoviePlayerDidEnterFullscreenNotification 
         *  MPMoviePlayerWillExitFullscreenNotification 
         *  MPMoviePlayerDidExitFullscreenNotification 
         *  ......具体查看API 
         */  
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finishNotification) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];  
          
    }  
      
    - (void)didClickPlayBarButtonAction{  
      
        //[self.navigationController pushViewController:self.moviePlayVC animated:YES];  
        [self presentViewController:self.moviePlayVC animated:YES completion:nil];  
        //  播放  
        [self.moviePlayVC.moviePlayer play];  
    }