gpt4 book ai didi

ios - SpriteKit : Preload sound file into memory before playing?

转载 作者:IT王子 更新时间:2023-10-29 08:19:28 25 4
gpt4 key购买 nike

只是想知道这是否可能。目前,我第一次在应用程序运行时播放声音文件时,在声音实际播放之前会有明显的延迟(比如它正在缓存它或其他东西)。在此之后它立即播放没有问题,但如果我完全关闭应用程序并重新启动它,延迟将在第一次播放声音时恢复。这是我用来播放声音的代码:

[self runAction:[SKAction playSoundFileNamed:@"mySound.caf" waitForCompletion:NO]];

最佳答案

您可以采用的一种方法是在场景开始时加载声音:

你的场景.h:

@interface YourScene : SKScene
@property (strong, nonatomic) SKAction *yourSoundAction;
@end

你的场景.m:

- (void)didMoveToView: (SKView *) yourView
{
_yourSoundAction = [SKAction playSoundFileNamed:@"yourSoundFile" waitForCompletion:NO];
// the rest of your init code
// possibly wrap this in a check to make sure the scene's only initiated once...
}

这应该会预加载声音,您应该能够通过在场景中调用操作来运行它:

[self runAction:_yourSoundAction];

我自己在有限的场景中尝试过,它似乎消除了延迟。

关于ios - SpriteKit : Preload sound file into memory before playing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22826675/

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