我想从我的服务器播放 mp3 文件,我执行以下操作:
NSURL *url = [NSURL URLWithString:item.audioUrl];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
self.player = [AVPlayer playerWithPlayerItem:playerItem];
self.player addObserver:self forKeyPath"status" options:0 context:nil];
self.hud = [[MBProgressHUD alloc]initWithFrame:CGRectMake(150, 5, 50, 50)];
self.hud.mode = MBProgressHUDModeIndeterminate;
[self.hud show:YES];
[self.containerView addSubview:self.hud];
这是我的 observeValueForKeyPath:
- (void)observeValueForKeyPathNSString *)keyPath ofObjectid)object changeNSDictionary *)change contextvoid *)context {
if (object == self.player && [keyPath isEqualToString"status"])
{
if (self.player.status == AVPlayerStatusReadyToPlay)
{
[self.hud hide:YES];
[self.player play];
.
.
.
现在的问题是,即使 AVPlayer 的状态已更改为“readyToPlay”,它仍然需要大约 2-3 秒才能开始播放,当然我的加载 Spinner 在音乐开始之前被隐藏了......任何想法?
试试 [self.player addObserver:self forKeyPath"status"options:0 context:nil];
方法 [self.playerItem addObserver:self forKeyPath"状态”选项:0 上下文:nil]
关于ios - AVPlayer 在状态达到 "ReadyToPlay"后仍有延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25288505/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |