Slow start for AVAudioPlayer the first time a sound is played

The delay seems to be related to instantiating AVAudioPlayer for the first time. If I load any audio, run [audioPlayer prepareToPlay] and then immediately release it, the load times for all of my other audio is very close to imperceptible. So now I’m doing that in applicationDidFinishLaunching and everything else runs well. I can’t find … Read more

iPhone: AVAudioPlayer unsupported file type

At long last i have found a solution to this problem! Instead of initializing the audio player with the NSData object, I saved the file to the Documents folder, and then initialized the player with the file URL //download file and play from disk NSData *audioData = [NSData dataWithContentsOfURL:someURL]; NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) … Read more

How to play mp3 audio from URL in iOS Swift?

Use AVPlayer instead of AVAudioPlayer to play remote content. As per documentation AVAudioPlayer needs mp3 file to play Audio. AVAudioPlayer not provide support for streaming. Try this code , its working fine for me func play(url:NSURL) { print(“playing \(url)”) do { let playerItem = AVPlayerItem(URL: url) self.player = try AVPlayer(playerItem:playerItem) player!.volume = 1.0 player!.play() } … Read more

iOS background audio not playing

add a key named Required background modes in property list (.plist) file .. as following picture.. may you get help.. and add following code in AppDelegate.h #import <AVFoundation/AVFoundation.h> #import <AudioToolbox/AudioToolbox.h> AppDelegate.m in application didFinishLaunchingWithOptions [[AVAudioSession sharedInstance] setDelegate:self]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; [[AVAudioSession sharedInstance] setActive:YES error:nil]; [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; UInt32 size = sizeof(CFStringRef); CFStringRef route; AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, … Read more

How do I start playing audio when in silent mode & locked in iOS 6?

You need to make couple of changes in plist file. i.e. 1) Set Required background mode to App plays audio 2) set Application does not run in background to YES. NSError *setCategoryErr = nil; NSError *activationErr = nil; [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&setCategoryErr]; [[AVAudioSession sharedInstance] setActive:YES error:&activationErr]; Then, you need to write these much code … Read more