gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:21:32 25 4
gpt4 key购买 nike

我想从我的服务器播放 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com