我有一个需要在后台播放音频的应用程序... 这是否可以使用Swift和SpriteKit与SKActions ... 或者它可能是另一种方式..
I have an app which needs to play audio in the background... Is this possible using Swift and SpriteKit with SKActions... Or is it possible another way..
向正确的方向微调会非常有帮助。
A nudge in the right direction would be very helpful.
推荐答案SKAction 非常容易使用声音,但有时你可能想要做更多。
SKAction is really easy to use with sounds, but sometimes you might want to do more.
在这种情况下,你会想要使用 AVAudioPlayer 代替它。
In that case, you would want to use AVAudioPlayerinstead of it.
为了不写自己的播放器,我建议你使用现有的。这是我已经使用的(SKTAudio): https:// github / raywenderlich / SKTUtils / blob / master / SKTUtils / SKTAudio.swift
In order to not write your own "player", I suggest you to use an existing one. Here is one I've already used (SKTAudio) : github/raywenderlich/SKTUtils/blob/master/SKTUtils/SKTAudio.swift
以下是如何使用它:
// For background audio (playing continuously) SKTAudio.sharedInstance().playBackgroundMusic("yourBackgroundMusic.mp3") // Start the music SKTAudio.sharedInstance().pauseBackgroundMusic() // Pause the music SKTAudio.sharedInstance().resumeBackgroundMusic() // Resume the music // For short sounds SKTAudio.sharedInstance().playSoundEffect("sound.wav") // Play the sound once正如你所看到的,你可以播放短音(就像你可能已经用 SKAction 那样),甚至可以播放循环播放的背景音乐。正在寻找。
As you can see, you'll be able to either play short sound (as you might already have done with SKAction) and even background music that will play in loop as you're looking for.
更多推荐
Swift SpriteKit在后台播放音频
发布评论