Swift SpriteKit在后台播放音频

编程入门 行业动态 更新时间:2024-10-25 10:32:15
本文介绍了Swift SpriteKit在后台播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个需要在后台播放音频的应用程序... 这是否可以使用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在后台播放音频

本文发布于:2023-07-11 09:08:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1093525.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   音频   Swift   SpriteKit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!