Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This cocoa-only solution uses existing audio files to play sounds. This method can be used to play any sound file. AVFoundation.framework will have to be added to your frameworks. You will have to define or remove the macros I use which are self explanatory.</p> <p>I added a category to AVAudioPlayer as follows:</p> <p>AVAudioPlayer+.h </p> <pre><code> #import &lt;AVFoundation/AVAudioPlayer.h&gt; @interface AVAudioPlayer ( CapSpecs ) + (AVAudioPlayer*) click; + (AVAudioPlayer*) tink; + (AVAudioPlayer*) tock; + (AVAudioPlayer*) withResourceName: (NSString*) aName; @end </code></pre> <p>AVAudioPlayer+.m</p> <pre><code> #import "AVAudioPlayer+.h" @implementation AVAudioPlayer ( CapSpecs ) + (AVAudioPlayer*) click { StaticReturn ( [AVAudioPlayer withResourceName: @"iPod Click"] ); } + (AVAudioPlayer*) tink { StaticReturn ( [AVAudioPlayer withResourceName: @"Tink"] ); } + (AVAudioPlayer*) tock { StaticReturn ( [AVAudioPlayer withResourceName: @"Tock"] ); } + (AVAudioPlayer*) withResourceName: (NSString*) aName { NSBundle* zBundle = [NSBundle bundleWithIdentifier: @"com.apple.UIKit"]; NSURL* zURL = [zBundle URLForResource: aName withExtension: @"aiff"]; (void) RaiseIfNil ( nil, zURL, ([SWF @"URL for %@",aName]) ); NSError* zError = nil; AVAudioPlayer* zAudio = [[AVAudioPlayer alloc] initWithContentsOfURL: zURL error: &amp;zError]; RaiseError ( nil, zError, @"AVAudioPlayer init error" ); #ifdef DEBUG // Apple records the console dump which occurs as a bug in the iOS simulator // all of the following commented code causes the BS console dump to be hidden int zOldConsole = dup(STDERR_FILENO); // record the old console freopen("/dev/null", "a+", stderr); // send console output to nowhere (void)[zAudio prepareToPlay]; // create the BS dump fflush(stderr); // flush the console output dup2(zOldConsole, STDERR_FILENO); // restore the console output #endif return zAudio; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload