ios - AVPlayer 在状态达到 "ReadyToPlay"后仍有延迟

标签 ios objective-c avplayer key-value-observing mbprogresshud

我想从我的服务器播放 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)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)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]; by [self.playerItem addObserver:self forKeyPath:@"状态”选项:0 上下文:无]

关于ios - AVPlayer 在状态达到 "ReadyToPlay"后仍有延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25288505/

相关文章:

ios - nils 在 MKLocalSearch 请求中发现解包可选值

iphone - 使标签栏在 iPhone 中可滚动?

iphone - 如何在 iphone 的表格单元格内显示多行文本?

swift - 如何检测 tvOS Remote 上的音量按钮按下

ios - 使用带有远程 URL 的 AVPlayer 的 MTAudioProcessingTap 进行 AVFoundation 音频处理

python - 如何在 swift 3 中集成 CoreML iOS 项目的自定义数据模型

objective-c - Subview 不会出现在 Mavericks 上;作品《山狮》

ios - 在 XCode 单 View 编译期间获取体系结构 i386 的 undefined symbol

iphone - AVPlayer和本地文件

ios - Core Motion 无法在 Xcode 7 Swift 2.0 中工作