1.新建single view工程,导入MediaPlayer库,导入一个视频文件test1.mp4

2.ViewController.h

    #import <UIKit/UIKit.h>   
    #import <MediaPlayer/MediaPlayer.h>   
       
    @interface ViewController : UIViewController {   
        MPMoviePlayerViewController *_playerVC;   
    }   
    @end  

2.ViewController.m
    #import "ViewController.h"   
       
    @implementation ViewController   
       
    - (void)viewDidLoad   
    {   
        [super viewDidLoad];   
           
        NSString *path = [[NSBundle mainBundle] pathForResource:@"test1" ofType:@"mp4"];   
        NSLog(@"%@", path);   
        NSURL *url = [NSURL fileURLWithPath:path];   
        _playerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:url];   
           
        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];   
        button.frame = CGRectMake(100, 100, 100, 40);   
        [button addTarget:self action:@selector(play) forControlEvents:UIControlEventTouchUpInside];   
        [self.view addSubview:button];   
    }   
       
    - (void)play   
    {   
        [self presentMoviePlayerViewControllerAnimated:_playerVC];   
        [_playerVC.moviePlayer play];   
    }   
       
    @end  

发布评论

分享到:

IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

iOS异步请求下载图片详解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。