/JSQSystemSoundPlayer

A fancy Obj-C wrapper for iOS System Sound Services

Primary LanguageObjective-COtherNOASSERTION

JSQSystemSoundPlayer

Build Status Version Status license MIT

A fancy Obj-C wrapper for iOS System Sound Services.

This class is a light-weight, drop-in component to play sound effects, or other short sounds in your iOS app. To determine your audio needs, see Best Practices for iOS Audio. Or, read the tl;dr version:

When your sole audio need is to play alerts and user-interface sound effects, use Core Audio’s System Sound Services.

Your sound files must be:

  • No longer than 30 seconds in duration
  • In linear PCM or IMA4 (IMA/ADPCM) format
  • Packaged in a .caf, .aif, or .wav file

If this does not fit your needs, then this control is not for you! See AVAudioPlayer, instead.

JSQSystemSoundPlayer Screenshot

Features

  • Play sound effects and alert sounds with a single line of code
  • "Play" vibration (if available on device)
  • Block-based completion handlers
  • Integration with NSUserDefaults to globally toggle sound effects in your app
  • Sweet and efficient memory management
  • Caches sounds (SystemSoundID objects) and purges on memory warning

Requirements

  • iOS 6.0+
  • ARC

Installation

pod 'JSQSystemSoundPlayer'

From source

  • Drag the JSQSystemSoundPlayer/ folder to your project
  • Add the AudioToolbox.framework to your project

Too cool for ARC?

  • Add the -fobjc-arc compiler flag to all source files in your project in Target Settings > Build Phases > Compile Sources.

Getting Started

[[JSQSystemSoundPlayer sharedPlayer] playSoundWithName:@"mySoundFile"
                                             extension:kJSQSystemSoundTypeAIF
                                            completion:^{
                                                // completion block code
                                            }];

And that's all!

String constants for file extensions provided for you:

  • kJSQSystemSoundTypeCAF
  • kJSQSystemSoundTypeAIF
  • kJSQSystemSoundTypeAIFF
  • kJSQSystemSoundTypeWAV

Need a setting in your app's preferences to toggle sound effects on/off? JSQSystemSoundPlayer can do that, too! There's no need to ever check the saved settings ([JSQSystemSoundPlayer sharedPlayer].on) before you play a sound effect. Just play a sound like in the example above. JSQSystemSoundPlayer respects whatever setting has been previously saved.

[[JSQSystemSoundPlayer sharedPlayer] toggleSoundPlayerOn:YES];

Also see the included demo project: SoundPlayerDemo.xcodeproj

Documentation

Documentation is available here via CocoaDocs. Thanks @CocoaDocs!

Donate

Support the developement of this free, open-source control! via Square Cash.

Send $1 Just saying thanks!

Send $5 This control is great!

Send $10 This totally saved me time!

How To Contribute

Please follow these sweet contribution guidelines.

Credits

Created by @jesse_squires, a programming-motherfucker.

Many thanks to the contributors of this project.

Apps Using This Control

Hemoglobe

iPaint uPaint

MUDRammer

Contact me to have your app listed here.

You are free to use this as you please. No attribution necessary, but much appreciated.

Copyright © 2013 Jesse Squires

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Bitdeli Badge