码迷,mamicode.com
首页 > 其他好文 > 详细

简单媒体播放器

时间:2015-06-12 23:36:05      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

//

//  ViewController.m

//  简单媒体播放器

//

//  Created by 殷婷婷 on 15-6-12.

//  Copyright (c) 2015年 lanou. All rights reserved.

//

 

#import "ViewController.h"

#import <MediaPlayer/MediaPlayer.h>

@interface ViewController ()

 

@property(nonatomic,strong)MPMoviePlayerController *player;

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    

    NSString *path = [[NSBundle mainBundle]pathForResource:@"1.mp4" ofType:nil];

    self.player = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:path]];

    self.player.view.frame = CGRectMake(0, 0, 320, 360);

    

    

}

 

 

- (IBAction)play:(UIButton *)sender {

    

    [self.view addSubview:self.player.view];

    

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(didFinishPlay) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player];

    [self.player play];

}

 

- (void)didFinishPlay{

    

    [self.player.view removeFromSuperview];

    [[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:self.player];

}

@end

 

简单媒体播放器

标签:

原文地址:http://www.cnblogs.com/yintingting/p/4572676.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!