//
Viewcontroller.m
Simple Media Player
//
Created by Sinting 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
Simple Media Player