我正在尝试在播放期间更改视频合成的布局(即其组件帧的变换).看起来有时它会起作用,并且视频合成无缝地改变为新的变换集,但有时它只是冻结并保持当前的变换.AVPlayer实例上没有状态代码更改,并且播放器或播放器项目都没有错误.
以前有人经历过这个吗?关于为什么会发生这种情况或如何解决这个问题的任何建议都将不胜感激.
一些代码如下所示.重要的一点是'playerItem.videoComposition = videoComposition',这是在点击视频时触发的(出于测试目的).
此问题的另一个解决方案是在单独的图层上显示视频,但视频必须同步,因此构图似乎是实现此目的的唯一方法.
@implementation VideoView
{
CGSize _videoSize;
CMTimeRange _videoFullRange;
AVMutableCompositionTrack * _compositionTrackVideoA;
AVMutableCompositionTrack * _compositionTrackVideoB;
}
+ (Class)layerClass
{
return [AVPlayerLayer class];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if ( self )
{
NSString * videoAPath = [[NSBundle mainBundle] pathForResource:@"cam09v2" ofType:@"mp4"];
NSString * videoBPath = [[NSBundle mainBundle] pathForResource:@"cam10v2_b" ofType:@"mp4"];
AVURLAsset * videoAAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:videoAPath] options:nil];
AVURLAsset * videoBAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:videoBPath] options:nil];
AVAssetTrack * videoATrack = [[videoAAsset tracksWithMediaType:AVMediaTypeVideo] lastObject];
AVAssetTrack * …Run Code Online (Sandbox Code Playgroud)