Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>answering my own question....</p> <p>further searching on SO led me to implementing this alternate solution:</p> <pre><code>- (void)setupAudio { [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil]; UInt32 doSetProperty = 1; AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &amp;doSetProperty); [[AVAudioSession sharedInstance] setActive: YES error: nil]; } </code></pre> <p>this was gleaned from <a href="https://stackoverflow.com/questions/1507541/avaudioplayer-turns-off-ipod-how-to-work-around/1507629#1507629">here</a></p> <p>**EDIT **UPDATED****</p> <p>I have since made this into a class that also pre-initialises the audio queue (useful in both simulator and device as it eliminates the startup lag from the playback of the first audio file. </p> <p>you can find the point1sec.mp3 here: <a href="http://www.xamuel.com/blank-mp3s/" rel="nofollow noreferrer">http://www.xamuel.com/blank-mp3s/</a></p> <pre><code>#import &lt;AVFoundation/AVFoundation.h&gt; #import "AudioToolbox/AudioServices.h" @interface sw_AVAudioPlayerSetup : NSObject &lt;AVAudioPlayerDelegate&gt; { } + (void)setupAudio ; + (void)setupSharedSession ; @end @implementation sw_AVAudioPlayerSetup + (void)setupSharedSession { static BOOL audioSessionSetup = NO; if (audioSessionSetup) { return; } [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil]; UInt32 doSetProperty = 1; AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &amp;doSetProperty); [[AVAudioSession sharedInstance] setActive: YES error: nil]; audioSessionSetup = YES; } + (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{ // delegate callback to release player [player release]; } + (void)setupAudio { [self setupSharedSession]; NSString *filepath = [[NSBundle mainBundle] pathForResource:@"point1sec" ofType:@"mp3"]; if ([[NSFileManager defaultManager] fileExistsAtPath:filepath]) { AVAudioPlayer* player = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:filepath] error:nil]; player.delegate = (id &lt;AVAudioPlayerDelegate&gt;) self; [player play]; } } </code></pre>
 

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