Spritekit停止声音 [英] Spritekit stopping sound

查看:240
本文介绍了Spritekit停止声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发使用苹果的SpriteKit库中的比赛,但我无法停止后声音就是已经开始播放。我一直在使用,以便从运行,但似乎没有任何停止播放声音停止Skaction从文档中列出的方法尝试。这些一直是试图阻止我的声音的尝试。

I'm currently developing a game using Apple's SpriteKit library but I'm unable to stop a sound after is has began playing. I have tried using the listed methods from the documentation in order to stop the Skaction from running but nothing seems to stop the sound from playing. These have been my attempts of trying to stop the sound.

//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

该musicNode很简单,运行的动作,虽然我直接从现场即尝试同样方法的SkpriteNode:现场播放的声音,后来尝试删除它。或者,也许动作不会停止,因为waitForCompletion设置为YES,但话又说回来,我试着用NO和相同的结果。莫不是天晓得使用AVaudioSession的sharedInstante停止声音的?我也尝试以下方法,但也失败了:

The musicNode is simply an SkpriteNode that runs the action, though I tried the same methods directly from the scene i.e: The scene plays the sound and later attempts to remove it. Or maybe the action will not stop because of the waitForCompletion set to YES, but then again, I tried with NO and same results. Could there be someway of using AVaudioSession's sharedInstante to stop the sound? I also tried the following method but also failed:

 [[AVAudioSession sharedInstance]setActive:FALSE error:nil];

感谢您的帮助!

推荐答案

Ive有使用SK音频..类似的问题,因此我已经回落使用AVFoundation。我发现这个前一阵子;它做的一切我需要做的,听起来像它可能会解决您的问题,以及!

Ive had similar issues using SK audio.. and as a result I have fallen back on using AVFoundation. I found this a while ago; it does everything I need it to do and sounds like it might fix your issue as well!

https://github.com/nicklockwood/SoundManager

这篇关于Spritekit停止声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆