AVPlayer无法在iOS 10上即时播放视频,而只能播放音频 [英] AVPlayer does not play video Instantly on iOS 10, while audio playing only

查看:99
本文介绍了AVPlayer无法在iOS 10上即时播放视频,而只能播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AVAssetExportSession创建视频,并在完成时播放视频. 但是Visual Part不能立即显示,而只有音频可以立即播放. 视觉部分经过大约20到30秒的延迟后出现.这是我播放视频的代码

I am creating video with AVAssetExportSession and playing video when it finishes. But Visual Part not showing instantly but only audio is playing instantly. Visual part comes after some delay about of 20 - 30 seconds. Here is my code to play video

-(void)playUrl:(NSURL *)vUrl{

[[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:[_avPlayer currentItem]];


_avAsset=nil;
_avPlayerItem=nil;
_avPlayer =nil;
[_avPlayerLayer removeFromSuperlayer];
_avPlayerLayer=nil;

_avAsset=[AVAsset assetWithURL:vUrl];
_avPlayerItem =[[AVPlayerItem alloc]initWithAsset:_avAsset];
_avPlayer = [[AVPlayer alloc]init]; //WithPlayerItem:_avPlayerItem];
[_avPlayer replaceCurrentItemWithPlayerItem:_avPlayerItem];
_avPlayerLayer =[AVPlayerLayer playerLayerWithPlayer:_avPlayer];
[_avPlayerLayer setFrame:CGRectMake(0, 0, viewAVPlayer.frame.size.width, viewAVPlayer.frame.size.height)];
[viewAVPlayer.layer addSublayer:_avPlayerLayer];
[_avPlayer seekToTime:kCMTimeZero];

[_avPlayer play];

_avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;



[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(repeatPlayer:) name:AVPlayerItemDidPlayToEndTimeNotification object:[_avPlayer currentItem]];



}

请让我知道是否有人知道它的答案.此代码在iOS 9上运行正常,但在iOS 10上却无法正常运行.

please let me know if anybody know its answer. this code is working perfectly in iOS 9 but not iOS 10. Thanks in advance.

推荐答案

尝试将AVPlayer的WaitsToMinimizeStalling属性自动设置为NO,以便立即开始播放.

Try to set automaticallyWaitsToMinimizeStalling property of AVPlayer to NO in order to start playback immediately.

_avPlayer = [[AVPlayer alloc]init]; //WithPlayerItem:_avPlayerItem];
_avPlayer.automaticallyWaitsToMinimizeStalling = NO;

但是,如果没有足够的内容来播放,则播放器可能会停顿.

But if sufficient content is not available for playing then player might stall.

Apple文档: https://developer.apple.com/reference/avfoundation/avplayer/1643482-自动等待stominimizestal .

希望这会有所帮助.

这篇关于AVPlayer无法在iOS 10上即时播放视频,而只能播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆