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:
- Start a game
- Wait for a phone call and go to background
- Phone call is finished (declined or interrupted by caller)
- Returning to foreground
After this, playing the sound from touchesBegan still works.
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
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...