调用播放时AVAudioPlayer滞后 [英] AVAudioPlayer lag when calling play

查看:73
本文介绍了调用播放时AVAudioPlayer滞后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在viewDidLoad中设置了AVAudioPlayer对象,根据Apple指南,将prepareToPlay称为viewDidLoad中的最后一行(我也尝试过awakeFromNib)。

I have set up an AVAudioPlayer object in viewDidLoad, as per the Apple guidelines, calling prepareToPlay as the last line in viewDidLoad (i have tried in awakeFromNib also).

当我按下我的播放按钮时,有一个暂停,因为它似乎加载文件,然后播放。

When i press my play button, there is a pause, as it would appear to load the file, then it plays.

在audioPlayerDidFinishPlaying中,我用不同的声音重新加载播放器,当再次点击播放时,文件会立即播放。

In audioPlayerDidFinishPlaying, i reload the player with a different sound, and when clicking play for a second time, the file plays instantly.

什么会导致玩家在第一场比赛中落后?

What would cause the player to lag on the first play?

谢谢。

推荐答案

音频系统运行在几个异步软件进程(音频单元,操作系统驱动程序等)和硬件系统(DMA,DAC,音频放大器电源等)上完成初始化,直到某些声音实际上一直播放到扬声器或耳机。

The audio system runs on several asynchronous software processes (audio units, OS drivers, etc.) and hardware systems (DMA, DACs, audio amp power supplies, etc.) that never really all completely finish initialization until some sound is actually played all the way out the speakers or earphones.

这是一种方法:创建一个包含半秒静音的声音文件。在应用启动时,当您的应用和视图控制器仍在加载时,使用AVAudioPlayer播放此静音文件。现在,当您的视图完成加载时,AVAudioPlayer应该准备好更快地播放后续的非静音,因为一些音频(静音)已经完全消失到扬声器。

Here's one method to do that: Create a sound file containing a half second of silence. On app start up, while your app and view controller are still loading, use AVAudioPlayer to play this file of silence. Now when your view finishes loading, AVAudioPlayer should be ready to play subsequent non-silent sounds much faster, since some audio (silence) has already already gone all the way out to the speakers.

这篇关于调用播放时AVAudioPlayer滞后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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