我有一个需要在后台播放音频的应用程序......
使用 Swift 和 SpriteKit 以及 SKActions 可以实现这一点吗?
或者还有其他方法吗..
朝着正确的方向推动将会非常有帮助。
SKAction
与声音一起使用确实很容易,但有时您可能想做更多。
在这种情况下,您需要使用AVAudioPlayer
而不是它。
为了不编写自己的“播放器”,我建议您使用现有的播放器。这是我已经使用过的一个(SKTAudio):https://github.com/raywenderlich/SKTUtils/blob/master/SKTUtils/SKTAudio.swift https://github.com/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
),甚至可以根据您的需要循环播放背景音乐。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)