使用AVPlayerItem
AVPlayer
AVPlayerLayer
实现视频播放功能
需要导入头文件#import <AVKit/AVKit.h>
效果图
代码示例
// 定义
@property (nonatomic, strong) AVPlayer *avPlayer;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UISlider *sliderView;
//
NSString *string = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mp4"];
NSURL *videoUrl = [NSURL fileURLWithPath:string];
// 创建AVPlayerItem
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:videoUrl];
//2.把AVPlayerItem放在AVPlayer上
self.avPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem];
//3 再把AVPlayer放到 AVPlayerLayer上
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlay