objective-c 多媒體 視頻播放器 改良版播放器(9.0 之前)

//ide

//  ViewController.matom

//  改良版播放器url

//spa

//  Created by dc009 on 15/12/29..net

//  Copyright © 2015 dc009. All rights reserved.3d

//orm


#import "ViewController.h"視頻

#import <MediaPlayer/MediaPlayer.h>get

@interface ViewController ()it

{

    UIButton *_button;

}

@property(nonatomic,strong)MPMoviePlayerViewController *moviePlayer;

@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    _button = [[UIButton alloc]initWithFrame:CGRectMake(100, 500, 200, 100)];

    [_button setTitle:@"播放" forState:UIControlStateNormal];

    [_button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

    [_button addTarget:self action:@selector(dianji) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:_button];

}

-(MPMoviePlayerViewController *)moviePlayer{

    if (!_moviePlayer) {

        //獲取視頻地址

        NSString *urlStr = [[NSBundle mainBundle]pathForResource:@"0" ofType:@"mp4"];

        NSURL *url = [NSURL fileURLWithPath:urlStr];

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

    }

    return _moviePlayer;

}


-(void)dianji{

    

    //爲了保證每次點擊都會從新建立播放器

    self.moviePlayer = nil;

    //模態窗口跳轉播放器,期間實例化播放器

    [self presentMoviePlayerViewControllerAnimated:self.moviePlayer];

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end

相關文章
相關標籤/搜索