PlayerViewControll .H
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface PlayerView : UIView UILabel *pageNumberLabel;
int pageNumber;
}
@property (nonatomic, retain) AVPlayer *player;
- (id)initWithPageNumber:(int)page;
PlayerView .M
#import "PlayerView.h"
@implementation PlayerView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {}
return self;
}
+ (Class)layerClass {
return [AVPlayerLayer class];
}
- (AVPlayer*)player {
return [(AVPlayerLayer *)[self layer] player];
}
- (void)setPlayer:(AVPlayer *)player {
[(AVPlayerLayer *)[self layer] setPlayer:player];
}
MainViewControll .H
#import <AVFoundation/AVFoundation.h>
#import "PlayerView.h"
@interface MainViewController : UIViewController {
IBOutlet PlayerView *playerView;
NSString *url;
AVPlayer *player;
NSMutableArray *arrIteam;
}
@property(nonatomic,retain) NSMutableArray *arrIteam;
@property (nonatomic, retain) AVPlayer *player;
@property(nonatomic ,retain)IBOutlet PlayerView *playerView;
PlayerView.M
#import "MainViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation MainViewController
@synthesize player,playerView,arrIteam;
- (void)viewDidLoad {
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"hello" ofType:@"mp4"];
AVPlayerItem *first = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:path1]];
arrIteam = [[NSMutableArray alloc] initWithObjects:first,second, third,fourth,nil];
player=[AVPlayer playerWithPlayerItem:[arrIteam objectAtIndex:i]];
[self.playerView setPlayer:player];
[player play];
[super viewDidLoad];
}