Iphone 如何在子视图中添加AVQueuePlayer以显示视图

Iphone 如何在子视图中添加AVQueuePlayer以显示视图,iphone,ios,objective-c,avplayer,Iphone,Ios,Objective C,Avplayer,我制作了一个AVQueuePlayer并添加了一些视频项目。当我运行应用程序时,视频会播放声音,但不会显示视频。我知道视频不显示的原因,因为我不知道如何在视图中添加AVQueuePlayer。请帮帮我 NSString *firstVideoPath = [[NSBundle mainBundle] pathForResource:@"3" ofType:@"m4v"]; NSString *secondVideoPa

我制作了一个AVQueuePlayer并添加了一些视频项目。当我运行应用程序时,视频会播放声音,但不会显示视频。我知道视频不显示的原因,因为我不知道如何在视图中添加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]];
Init 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"
#导入
#导入“AVFoundation/AVFoundation.h”