Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/trifl/Chirp
The easiest way to prepare, play, and remove sounds in your Swift app!
https://github.com/trifl/Chirp
Last synced: 3 months ago
JSON representation
The easiest way to prepare, play, and remove sounds in your Swift app!
- Host: GitHub
- URL: https://github.com/trifl/Chirp
- Owner: trifl
- License: mit
- Created: 2015-09-01T01:45:26.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-05-29T00:27:12.000Z (over 5 years ago)
- Last Synced: 2024-04-24T19:01:27.378Z (6 months ago)
- Language: Swift
- Homepage: http://www.trifl.co
- Size: 396 KB
- Stars: 307
- Watchers: 7
- Forks: 22
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Chirp - The easiest way to prepare, play, and remove sounds in your Swift app! (Media / Audio)
- awesome-ios-star - Chirp - The easiest way to prepare, play, and remove sounds in your Swift app! (Media / Audio)
README
# Chirp
The easiest way to prepare, play, and remove sounds in your Swift app!
##Installation
###CocoaPods Installation
Chirp is available on CocoaPods. Just add the following to your project Podfile:```
pod 'Chirp', '~> 1.2'
```###Non-CocoaPods Installation
You can drop Chirp.swift directly into your project, or drag the Chirp project into your workspace.### Sample code
`prepareSound` is used to preload a sound into memory. This increases the retain count of the sound by 1. You must call this method before calling playSound
```swift
/* MyViewController.swift */override func viewDidLoad() {
super.viewDidLoad()
// Load sounds into memory
Chirp.sharedManager.prepareSound("boop") // default extension is .wav
Chirp.sharedManager.prepareSound("ding.mp3") // so other extensions you must name explicitly
}
````playSound` plays the preloaded sound
```swift
func submitButtonTouched(button: UIButton) {
// Since the sound is already loaded into memory, this will play immediately
Chirp.sharedManager.playSound("boop")
// example function that might get called when you touch a button
submitForm()
}
````removeSound` removes the sound from memory
```swift
deinit {
// Cleanup is really simple!
Chirp.sharedManager.removeSound("boop")
Chirp.sharedManager.removeSound("ding.mp3")
Chirp.sharedManager.removeSound("oops.mp3")
// If you never loaded the sounds, e.g. viewDidLoad wasn't called, or submission never failed or succeeded,
// that's ok, because these will function as no-ops
}
```Enjoy! I know sound management can be a little annoying. Hopefully this helps your project out a little bit.