#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface MediaPlayerController: UIViewController
{
AVPlayerLayer *videoPlayerLayer;
AVPlayer *player;
NSTimer *timer;
}
@property(nonatomic, retain) AVPlayerLayer *videoPlayerLayer;
@property (strong, nonatomic) IBOutlet UIView *vidoView;
-(void)onPlay;
@end
#import "MediaPlayerController.h"
@implementation MediaPlayerController
@synthesize videoPlayerLayer;
@synthesize vidoView;
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"splash-30s" ofType:@"mp4"];
NSURL *videoUrl = [NSURL fileURLWithPath:videoPath];
player = [[AVPlayer alloc] initWithURL:videoUrl];
//self.view.frame = CGRectMake (0, 0, 1024, 748);
videoPlayerLayer=[AVPlayerLayer playerLayerWithPlayer:player];
self.view.backgroundColor=[UIColor colorWithWhite:1.0 alpha:1.0];
videoPlayerLayer.videoGravity = AVLayerVideoGravityResize;
videoPlayerLayer.frame = CGRectMake (0, 0, 320, 400);
[vidoView.layer addSublayer:videoPlayerLayer];
timer=[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(onPlay) userInfo:nil repeats:NO];
}
-(void)onPlay
{
videoPlayerLayer.hidden = NO;
[player play];
}