问题描述
我试图找出为什么 playSoundFileNamed 的接收到两个连续的电话后,无法正常工作。其实它的工作原理是接到第一个电话之后。再现步骤是:
I am trying to figure out why playSoundFileNamed doesn't work after receiving two consecutive phone calls. Actually it works only after the first phone call is received. Reproducing steps are:
- 开始游戏
- 等待一个电话并转到后台
- 电话呼叫结束(拒绝或中断调用者)
- 返回到前台
在此之后,从播放声音 的touchesBegan 的仍然有效。
After this, playing the sound from touchesBegan still works.
当我重复这些步骤从上面(第一步是跳过),从机制的touchesBegan停止工作。不知道为什么会这样......这里是code能产生描述的行为:
When I repeat the steps from above (first step is skipped), mechanism from touchesBegan stops working. Not sure why is this happening...Here is the code which can produce described behaviour:
@interface GameScene()
@property (nonatomic, strong) SKAction *sound;
@end
@implementation GameScene
-(void)didMoveToView:(SKView *)view {
self.sound = [SKAction playSoundFileNamed:@"sound1.wav" waitForCompletion:NO];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
[self runAction:self.sound];
}
@end
我知道有与此相关的SO一些问题,但鉴于答案相关的解决方法。 我没有兴趣的解决方法,而为什么会出现这种情况?是它在某种程度上关系到AVAudioSession? (可能没有)我知道我可以使用AVAudioPlayer作为一种解决方法,但仍然不知道有多少是用于高性能打了很多简单的短声音...
I know there are some questions related to this on SO, but given answers are related to workarounds. I am not interested in workaround, but rather why is this happening? Is it somehow related to AVAudioSession ? (probably not) I know I could use AVAudioPlayer as a workaround, but still not sure how much is that performant for playing a lot of simple short sounds...
推荐答案
该SKAction playSoundFileNamed
是越野车的问候背景和前景之间的过渡程序。这就是为什么你有这个问题的原因。我不知道如果这个问题已经在iOS中9得到纠正。
The SKAction playSoundFileNamed
is buggy in regards to the app transitioning between background and foreground. That's the reason why you are having this issue. I am not sure if this problem has been corrected in iOS 9.
至于解决方法,你说你没兴趣,但我会包括一个完成的缘故。使用AVAudioPlayer代替SKAction。 AVAP已经停止,并开始根据您的应用程序的状态(通过其代表)的能力。
As for a workaround, you stated you're not interest but I will include one for completion's sake. Use AVAudioPlayer instead of SKAction. AVAP has the ability to stop and start (using its delegates) based on your app's state.
这篇关于SKAction playSoundFileNamed没有接收到两个连续的电话后工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!