Detecting the iPhone’s Ring / Silent / Mute switch using AVAudioPlayer not working?

Well I found the answer thanks to someone from the Developer Forums, and you guys aren’t gonna like it! I’ve had a response from Apple on this. They’ve said they don’t and never have provided a method for detecting hardware mute switch and don’t intend to do so. 🙁 IMO there is definitely value in … Read more

UISlider to control AVAudioPlayer

Shouldn’t be a problem – just set the slider to continuous and set the max value to your player’s duration after loading your sound file. Edit I just did this and it works for me… – (IBAction)slide { player.currentTime = slider.value; } – (void)updateTime:(NSTimer *)timer { slider.value = player.currentTime; } – (IBAction)play:(id)sender { NSURL *url … Read more

How to get AVAudioPlayer output to the speaker

I realize this question is fairly old but when I was struggling with the same problem I found a simple solution that hopefully will help anyone else looking to use the louder media speakers as opposed to the receiver speakers. The method I used was setting up the audio session with the DefaultToSpeaker option in … Read more

Play music in the background using AVAudioplayer

I had solved this question by referring iOS Application Background tasks and make some changes in .plist file of our application.. Update write this code in your controller’s view did load method like this – (void)viewDidLoad { NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@”in-the-storm” ofType:@”mp3″]]; AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback … 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

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

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

AVAudioPlayer fade volume out

Here’s how I’m doing it: -(void)doVolumeFade { if (self.player.volume > 0.1) { self.player.volume = self.player.volume – 0.1; [self performSelector:@selector(doVolumeFade) withObject:nil afterDelay:0.1]; } else { // Stop and get the sound ready for playing again [self.player stop]; self.player.currentTime = 0; [self.player prepareToPlay]; self.player.volume = 1.0; } } . 11 years later: do note that setVolume#fadeDuration now … Read more

Play sound on iPhone even in silent mode [duplicate]

It’s not advisable, but who am I to say you can’t do it. You may have a good reason to be playing sound. If you are using Audio Sessions, then include <AVFoundation/AVFoundation.h> at the start of your file and [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil]; should do the trick. Note if you play music or … Read more

Are headphones plugged in? iOS7

This should work, but I cannot test it right now, I’ll do in the evening. – (BOOL)isHeadsetPluggedIn { AVAudioSessionRouteDescription* route = [[AVAudioSession sharedInstance] currentRoute]; for (AVAudioSessionPortDescription* desc in [route outputs]) { if ([[desc portType] isEqualToString:AVAudioSessionPortHeadphones]) return YES; } return NO; }

tech