قالب وردپرس درنا توس
Home / IOS Development / # 304: Simple audio playback with SwiftySound 🔊 – Small pieces of cocoa

# 304: Simple audio playback with SwiftySound 🔊 – Small pieces of cocoa



Issue

Topics

Apple delivers lots of good APIs to play audio in our apps .

They offer a wealth of good functionality but also a good deal of complexity .

Often we do not need all that power. Perhaps we add sound effects or sound feedback to one of our user interfaces, or maybe we just need to loop some background music in the menu in our video game.

Today we are checking out a new library from Adam Cichy called SwiftySound that can help us simplify our audio playback code. Let's have a look.

First, Simple Playback:

  Sound .   game   (  file :    "unscheduled-offworld-activation.wav" ] 

or

  Audio .   Games   ]   url :    someURL ) 

That's it. Yes, really.

This kind of UIImage proper simplicity has always been kind of shortcomings from : [main menu] 1

9659014] fileExtension : "wav" numberOfLoops : 1 )

We could pass in Int here to loop the music, but we have passed -1 to indicate we will end forever.

One of the most useful features of SwiftySound is the inclusion of a UserDefaults Perspective flag to continue the user's preference for audio playback that is enabled or disabled.

We can use this on the app settings screen to allow users to easily enable / disable audio effects globally. [19659000] . enabled = soundsSwitch . on

The value is then automatically renewed and respected over app launches. A nice touch of SwiftySounds author, Adam Cichy. [19659000] We are not required to use this singleton Sound copy by the way, we can always make a Sound example and send it around

  la    audio    =    Audio   [  url :    soundEffectURL ) 

Then Later:

  audio ]   play   () 

] Last but not least, SwiftySound appears to be a single Swift file.

It is great to see this kind of force and flexibility in such a small addiction .

😍 More like this, please!

Full documentation for SwiftySound is on git.io/swiftysound


Source link