#import "ViewController.h"#import#import@interface ViewController ()@property (nonatomic,strong) AVPlayer *player;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //.mp4 // NSString *playStr = @"http://v.cctv.com/flash/mp4video6/TMS/2011/01/05/cf752b1c12ce452b3040cab2f90bc265_h264818000nero_aac32-1.mp4"; NSString *playStr = @"http://player.video.qiyi.com/4cc27d815269fa55fa134fdd3992c85a/0/300/w_19rtqzch9t.swf-albumId=8098183709-tvId=8098183709-isPurchase=0-cnId=7.mp4"; NSURL *playURL = [NSURL URLWithString:playStr]; // 设置播放的项目 AVPlayerItem *item = [[AVPlayerItem alloc]initWithURL:playURL]; self.player = [[AVPlayer alloc]initWithPlayerItem:item]; // 设置播放页面 AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.player]; // 设置播放页面的大小 layer.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 250); layer.backgroundColor = [UIColor cyanColor].CGColor; // 设置播放窗口和当前视图之间的比例显示内容 layer.videoGravity = AVLayerVideoGravityResizeAspect; [self.view.layer addSublayer:layer]; // 设置播放进度的默认值 // 设置默认音量 self.player.volume = 3.0f;}- (IBAction)againButton:(id)sender { }- (IBAction)stopButton:(id)sender { [self.player pause];}- (IBAction)playButton:(id)sender { [self.player play];}
网友评论