AVAudioPlayer 从 Springboard 返回时跳过

发布于 2024-11-08 23:12:28 字数 793 浏览 0 评论 0原文

我的应用程序期间不断播放音频。当我按下按钮返回 Springboard 然后恢复我的应用程序时,我出现了一些奇怪的行为。音频将继续播放,但每半秒左右就会跳过/切断。暂停和恢复音频似乎没有效果。

我正在使用 AVAudioPlayers 来播放我的音频。这是播放它们的代码...

player = [[AVAudioPlayer alloc] initWithData:data error:&err];
[player play];
player.numberOfLoops = loops;

mSimpleSoundList.push_back(player);

然后在“applicationWillResignActive”中我调用...

const uint32 size = mSimpleSoundList.size();
for(unsigned int i = 0; i < size; ++i) {

    AVAudioPlayer* curElement = mSimpleSoundList.at(i);
    [curElement pause];
}

然后是重新启动时的代码..

const uint32 size = mSimpleSoundList.size();
for(unsigned int i = 0; i < size; ++i) {

    AVAudioPlayer* curElement = mSimpleSoundList.at(i);
    [curElement play];
}

I have audio constantly playing during my application. I am having some odd behavior when I press the button to return to Springboard then resume my applications. The Audio will continue playing but will skip/cutout every half second or so. Pausing and resuming the audio seems to have no effect.

I am using AVAudioPlayers to play my Audio. Here is the code to play them...

player = [[AVAudioPlayer alloc] initWithData:data error:&err];
[player play];
player.numberOfLoops = loops;

mSimpleSoundList.push_back(player);

Then in the "applicationWillResignActive" I call...

const uint32 size = mSimpleSoundList.size();
for(unsigned int i = 0; i < size; ++i) {

    AVAudioPlayer* curElement = mSimpleSoundList.at(i);
    [curElement pause];
}

followed by this code on restart..

const uint32 size = mSimpleSoundList.size();
for(unsigned int i = 0; i < size; ++i) {

    AVAudioPlayer* curElement = mSimpleSoundList.at(i);
    [curElement play];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文