title: iPhone : Looping Audio stops after 4 mins
body: <p>I am making a count down timer which plays a "beep" sound for every second counting through an NSTimer. The app must be awake for a max period of 90min and play the repeating beep sound until the timer is invalidated. From the plist i selected "UIbackground Modes App plays audio" and also added to the delegate.m <code>[UIApplication sharedApplication].idleTimerDisabled = YES;</code> in order to keep my timer on screen. The problem is that <strong>after 4 minutes the repeating sound stops</strong>. Everything else is working, the app seems awake, the label showing the countdown updates itself. In order to restore audio you have to quit and re-launch the app. 
  The problem occurs in both the simulator and the device (iPhone 3G). 
  I am using xcode 4 if that matters.
  Here is my code:</p>
  
  <pre><code>NSString *path = [[NSBundle mainBundle]
                     pathForResource:@"beep" ofType:@"mp3"];
   AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
   [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
   UIBackgroundTaskIdentifier bgTask = [[UIApplication sharedApplication]beginBackgroundTaskWithExpirationHandler:nil];
   [[UIApplication sharedApplication] endBackgroundTask:bgTask];
   [audioPlayer play];
  </code></pre>
  
  <p>Of course, i have imported the libraries</p>
  
  <pre><code>#import &lt;AVFoundation/AVFoundation.h&gt;
  #import &lt;AudioToolbox/AudioToolbox.h&gt;
  </code></pre>
  
  <p>p.s. I am reading for hours topics about background audio and tested nearly everything i could find but nothing worked for me. If somebody can help me, please have in mind that i am very new to programming. Thanks in advance.</p>