rom*_*her 5 audio avaudiosession sprite-kit skaction
我目前正在使用Apple的SpriteKit库开发游戏,但是在开始播放之后我无法停止声音.我已经尝试使用文档中列出的方法来阻止Skaction运行,但似乎没有任何东西阻止播放声音.这些是我试图阻止声音的尝试.
//Playing sound action:
SKAction *music = [SKAction playSoundFileNamed:@"menu.wav" waitForCompletion:YES];
[musicNode runAction:[SKAction repeatActionForever:[SKAction sequence:@[
music,
[SKAction waitForDuration:0],
]]] withKey:@"MUSIC_PLAYING"];
//Later when i want to stop the sound:
[musicNode removeActionForKey:@"MUSIC_PLAYING"]; //Removing the action from the node
[musicNode runAction:[SKAction waitForDuration:0] withKey:@"MUSIC_PLAYING"]; //"Overriding" with another action with the same key
[musicNode removeAllActions]; //Removing all actions from the node
[musicNode removeFromParent]; //Removing the node from the parent
Run Code Online (Sandbox Code Playgroud)
musicNode只是一个运行动作的SkpriteNode,虽然我直接从场景中尝试了相同的方法,即:场景播放声音,然后尝试删除它.或者,由于waitForCompletion设置为YES,动作不会停止,但是再次尝试使用NO和相同的结果.有没有办法使用AVaudioSession的sharedInstante来停止声音?我也试过以下方法但也失败了:
[[AVAudioSession sharedInstance]setActive:FALSE error:nil];
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我在使用 SK audio 时也遇到过类似的问题。因此我又转而使用 AVFoundation。我不久前发现了这个;它可以完成我需要它做的所有事情,听起来它也可以解决您的问题!
https://github.com/nicklockwood/SoundManager
| 归档时间: |
|
| 查看次数: |
2444 次 |
| 最近记录: |