作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我制作了一个 AVQueuePlayer 并添加了一些视频项。当我运行应用程序时,视频的声音播放但视频不显示。我知道视频不显示的原因,这是因为我不知道如何在 View 中添加 AVQueuePlayer。请帮助我
NSString *firstVideoPath = [[NSBundle mainBundle]
pathForResource:@"3" ofType:@"m4v"];
NSString *secondVideoPath = [[NSBundle mainBundle]
pathForResource:@"2" ofType:@"m4v"];
NSString *thirdVideoPath = [[NSBundle mainBundle]
pathForResource:@"3" ofType:@"m4v"];
AVPlayerItem *firstVideoItem = [AVPlayerItem playerItemWithURL:
[NSURL fileURLWithPath:firstVideoPath]];
AVPlayerItem *secondVideoItem = [AVPlayerItem playerItemWithURL:
[NSURL fileURLWithPath:secondVideoPath]];
AVPlayerItem *thirdVideoItem = [AVPlayerItem playerItemWithURL:
[NSURL fileURLWithPath:thirdVideoPath]];
self.queuePlayer = [AVQueuePlayer queuePlayerWithItems:
[NSArray arrayWithObjects:firstVideoItem,
secondVideoItem,thirdVideoItem,nil]];
[self.playerView setPlayer:self.queuePlayer];
[self.queuePlayer play];
最佳答案
首先,抓取所有路径:
NSString *firstVideoPath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"m4v"];
NSString *secondVideoPath = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"mp4"];
NSString *thirdVideoPath = [[NSBundle mainBundle] pathForResource:@"3" ofType:@"m4v"];
AVPlayerItem *firstVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:firstVideoPath]];
AVPlayerItem *secondVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:secondVideoPath]];
AVPlayerItem *thirdVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:thirdVideoPath]];
初始化AVQueuePlayer:
AVQueuePlayer *queuePlayer = [AVQueuePlayer queuePlayerWithItems:@[firstVideoItem, secondVideoItem,thirdVideoItem]];
最后使用图层将所有电影显示为播放列表。
AVPlayerLayer *layer = [AVPlayerLayer layer];
[layer setPlayer:queuePlayer];
[layer setFrame:CGRectMake(10, 10, 300, 200)];
[layer setBackgroundColor:[UIColor redColor].CGColor];
[layer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[self.view.layer addSublayer:layer];
[queuePlayer play];
不要忘记添加框架:
#import <QuartzCore/QuartzCore.h>
#import "AVFoundation/AVFoundation.h"
关于iphone - 如何在 subview 中添加 AVQueuePlayer 以显示 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16677249/
我是一名优秀的程序员,十分优秀!