標籤:
//
// 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
簡單媒體播放器