ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - adamcichy/SwiftySound: SwiftySound is a simple library that lets you play sounds with a single line of code.
SwiftySound is a simple library that lets you play sounds with a single line of code. - adamcichy/SwiftySound
Visit Site

GitHub - adamcichy/SwiftySound: SwiftySound is a simple library that lets you play sounds with a single line of code.

GitHub - adamcichy/SwiftySound: SwiftySound is a simple library that lets you play sounds with a single line of code.

SwiftySound

CocoaPods License CocoaPods CocoaPods Platforms Carthage Compatible SPM ready codebeat

Overview

SwiftySound is a simple library that lets you deal with Swift sounds easily.

Static methods
Sound.play(file: "dog.wav")
Sound.play(url: fileURL)

More advanced example:

Sound.play(file: "dog", fileExtension: "wav", numberOfLoops: 2)

The above will play the sound three times.

Specify a negative number of loops to play the sound continously in an infinite loop:

Sound.play(file: "dog", fileExtension: "wav", numberOfLoops: -1)

Stop currently playing sounds:

Sound.stopAll()

Enable/disable all sounds:

Sound.enabled = true
Sound.enabled = false

The value of Sound.enabled property will be automatically persisted in UserDefaults and restored on the next launch of your app.

Change sound categories. SwiftySound provides a simple way of changing sound category:

Sound.category = .ambient

This changes the category of the underlying shared AVAudioSession instance. The default value is SoundCategory.ambient. Due to AVAudioSession architecture, this property is not available on macOS.

Creating instances of Sound class

You can also create an instance of a Sound class and store it somewhere in your app.

let mySound = Sound(url: fileURL)
mySound.play()

Creating an instance has more benefits like the ability to adjust the volume and playback callbacks.

Change the volume

You can change the volume of each Sound instance.

mySound.volume = 0.5

The value of volume property should be between 0.0 and 1.0, where 1.0 is the maximum.

Callbacks

You can pass a callback to the play method. It will be played after the sound finished playing. For looped sounds, the callback will be called once after the last loop has been played.

mySound.play { completed in
    print("completed: \(completed)")
}

Features

  • Playing single sounds
  • Loops
  • Infinite loops
  • Playing the same sound multiple times simultaneously
  • Stopping all sounds with a global static method
  • Ability to pause and resume
  • Adjusting sound volume
  • Callbacks
  • Global static variable to enable/disable all sounds

Requirements

  • Swift 5
  • Xcode 15 or later
  • iOS 12.0 or later
  • tvOS 12.0 or later
  • macOS 10.13 or later

For Xcode 8 and Swift 3 support, please use SwiftySound version 0.7.0. For Xcode 9 and Swift 4 support, please use SwiftySound version 1.0.0. For Xcode 10 and iOS 9 support, please use SwiftySound version 1.2.0.

Installation

Installation with CocoaPods

CocoaPods is a dependency manager which automates and simplifies the process of using third-party libraries in your projects. See the Get Started section for more details.

Podfile

platform :ios, '12.0'
use_frameworks!
pod 'SwiftySound'

Installation with Carthage

Carthage is a lightweight dependency manager for Swift and Objective-C. It leverages CocoaTouch modules and is less invasive than CocoaPods.

To install with carthage, follow the instruction on Carthage

Cartfile

github "adamcichy/SwiftySound"

Installation with Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. Just add the url of this repo to your Package.swift file as a dependency:

import PackageDescription

let package = Package(
    name: "YourPackage",
    dependencies: [
        .Package(url: "https://github.com/adamcichy/SwiftySound.git",
                 majorVersion: 0)
    ]
)

Then run swift build and wait for SPM to install SwiftySound.

Manual installation

Drop the Sound.swift file into your project, link against AVFoundation.framework and you are ready to go.

Licenses

SwiftySound is licensed under the MIT License.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory