我正在使用objective-c开发一个应用程序。
在我的UIViewController中
.h文件
@property(weak,nonatomic)IBOutlet UIView *vvv;
.m文件
// to play the video
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"alphabet learning splash" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
self.avPlayer = [AVPlayer playerWithURL:fileURL];
self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
AVPlayerLayer *videoLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
[_vvv.layer addSublayer:videoLayer];
[self.view addSubview:_vvv];
[ self.avPlayer play];
但视频没有显示在vvv的UIView中。如何设置?
答案 0 :(得分:0)
尝试设置界限
// to play the video
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"alphabet learning splash" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
self.avPlayer = [AVPlayer playerWithURL:fileURL];
self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
AVPlayerLayer *videoLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
[_vvv.layer addSublayer:videoLayer];
[self.view addSubview:_vvv];
_vvv.frame = self.bounds;
[ self.avPlayer play];