iOS之視訊的三種播放方式

夢筆隨心發表於2016-05-13

//

//  ViewController.m

//  視訊播放

//

//  Created by 李江 on 16/5/13.

//  Copyright © 2016 李江. All rights reserved.

//


#import "ViewController.h"

#import <MediaPlayer/MediaPlayer.h>

#import <AVKit/AVKit.h>

#import <AVFoundation/AVFoundation.h>

@interface ViewController ()

{

    MPMoviePlayerController *moviePlayerController;

    MPMoviePlayerViewController *moviePlayerViewController;

    AVPlayerViewController *playerViewController;

}

@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    [self AVPlayerViewController];

    UIButton *startBtn = [[UIButton alloc]initWithFrame:CGRectMake(200, 200, 80, 80)];

    startBtn.backgroundColor = [UIColor redColor];

    [startBtn addTarget:self action:@selector(buttona) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:startBtn];

    }

//mpMoviePlayerController

-(void)mpMoviePlayerController{

    NSURL *url = [NSURL URLWithString:@"http://127.0.0.1/promo_full.mp4"];

    moviePlayerController = [[MPMoviePlayerController alloc]initWithContentURL:url];

    moviePlayerController.view.frame = CGRectMake(0, 0, 414, 736);

    [self.view addSubview:moviePlayerController.view];

    [moviePlayerController play];

}

//MPMoviePlayerViewController

-(void)mpMoviePlayerViewController{

    NSURL *url = [NSURL URLWithString:@"http://127.0.0.1/promo_full.mp4"];

    moviePlayerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];

    

    

    [self presentViewController:moviePlayerViewController animated:YES completion:nil];


}

//AVPlayerViewController

-(void)AVPlayerViewController{

    NSURL *url = [NSURL URLWithString:@"http://127.0.0.1/promo_full.mp4"];

    playerViewController = [[AVPlayerViewController alloc]init];

    playerViewController.player = [[AVPlayer alloc]initWithURL:url];

    

    

}

-(void)buttona{

    [self presentViewController:playerViewController animated:YES completion:nil];


}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end



相關文章