MJLOVE / JSQSystemSoundPlayer

A fancy Obj-C wrapper for Cocoa System Sound Services

Home Page:http://www.jessesquires.com/JSQSystemSoundPlayer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSQSystemSoundPlayer

Build Status Version Status license MIT codecov.io Carthage compatible

A fancy Obj-C wrapper for Cocoa System Sound Services, for iOS and OS X.

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.

screenshot ios     screenshot osx

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 instances) and purges on memory warning
  • Works with Swift! (v2.0+)

Requirements

  • iOS 6.0+
  • OS X 10.7+
  • ARC

Installation

pod 'JSQSystemSoundPlayer'
github "jessesquires/JSQSystemSoundPlayer"

Manually

  1. Add the JSQSystemSoundPlayer/ folder to your project
  2. Add AudioToolbox.framework

Getting Started

#import <JSQSystemSoundPlayer/JSQSystemSoundPlayer.h>
// or
@import JSQSystemSoundPlayer;

Playing sounds

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

And that's all!

String constants for file extensions provided for you:

  • kJSQSystemSoundTypeCAF
  • kJSQSystemSoundTypeAIF
  • kJSQSystemSoundTypeAIFF
  • kJSQSystemSoundTypeWAV

Toggle sounds effects settings on/off

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];

Specifying a bundle

Need to load your audio resources from a specific bundle? JSQSystemSoundPlayer uses the main bundle by default, but you can specify another.

NOTE: for each sound that is played JSQSystemSoundPlayer will always search the last specified bundle. If you are playing sound effects from multiple bundles, you will need to specify the bundle before playing each sound.

[JSQSystemSoundPlayer sharedPlayer].bundle = [NSBundle mainBundle];

Demo project

The included example app, Example.xcodeproj, exercises all functionality of this framework. There are applications for iOS as well as OS X.

For a good time

while (1) {
    [[JSQSystemSoundPlayer sharedPlayer] playVibrateSound];
}

Documentation

Read the fucking docs. Generated with appledoc. Hosted by GitHub Pages.

More information on the gh-pages branch.

Contribute

Please follow these sweet contribution guidelines.

Credits

Created and maintained by @jesse_squires

Apps using this library

License

JSQSystemSoundPlayer is released under an MIT License. See LICENSE for details.

Copyright © 2015 Jesse Squires.

Please provide attribution, it is greatly appreciated.

About

A fancy Obj-C wrapper for Cocoa System Sound Services

http://www.jessesquires.com/JSQSystemSoundPlayer

License:Other


Languages

Language:Objective-C 97.9%Language:Ruby 2.1%