Checking Microphone Volume in iPhone - iphone

How to check whether microphone is muted before recording audio in iPhone?

Actually, you don't have to. You have to "warn" AVAudioSession that you are going to record a bit of Audio. Doing so, even if you are muted (on the IPhone, I Have not tested this with any external device) you will be able to record your audio... here is the piece of code that does that:
[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryRecord
error: &error];
it even records with a higher volume.
Best of luck...

Related

Ignore output produced

I am developing an iOS app that monitors input every second. This app also produces music at the same time. The input and the output are interfering. Is there a way to prevent the output from being picked up by the input unit?
Have a look at AVAudioSession:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error: &error];
[[AVAudioSession sharedInstance] setActive:YES error: &error];
For AVAudioSessionCategoryPlayAndRecord the docs say:
This category is appropriate for simultaneous recording and playback, and also for apps that record and play back but not simultaneously.

unable to get the Audio output in iOS

I have a codebase which plays audio and video perfectly. I have converted that into a small framework and started using it as a part of another code. When i do this, there is no audio output.... I am unable to hear any audio output while it is being played. All the Audio player delegate methods are being called but there is no sound. The same is happening with Videos as well. All the videos are being played with out sound. Its like watching a silent movie.... Any ideas? I am using AVAudioPlayer for playing audio files and MPMoviePlayerController for playing videos.
edit : This happens only on device. It works all fine in simulator
Just came across this post, I was doing the same thing, and actually AVAduioSession is needed to play audio thru speaker/headset. So having AVAudioSession is a must.
//REALLY NEED THIS LINE FOR MUSIC TO PLAY TO SPEAKER
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
and for background playing, add these 2 lines and change setting in plist to allow background mode
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
So stupid of me.... The problem was with the volume button on iPad. The volume button in iPad with iOS 5 has some weird bug. It does not update itself when we toggle the button between screen lock and audio output. I guess this is bug from apple and filed a bug. Hope they solve this in their next update.

AudioSession - want to stop everything being played in background?

I got a need to stop (or mute at least) music/sound that is played in iPhone.
Important: I want my app will do that it even if is in background-state!
I'm using:
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategorySoloAmbient error:nil]];
[[AVAudioSession sharedInstance] setActive: YES];
The issue is that everything is being stopped, even streaming music from some other app, but only if app is in FOREGROUND. As wrote before, I want it to be working also in BACKGROUND.
I did simple research and realized it's somehow possible, these apps prove:
App Store - Streaming Music Timer or
App Store - Music Sleep Timer
I guess my solution with SoloAmbient can be not so perfect and it may be a wrong way.
Does anybody know how could I stop/sleep/pause/mute global music even if app will be in background state?
These apps I pointed out are doing basically this thing...
You need to enable the audio background mode.
Add the Required Background Modes key to your app's Info.plist and add the App Plays Audio key to it.
See this tutorial for more.
EDIT Also, you probably want the AVAudioSessionCategoryPlayback category, not AVAudioSessionCategorySoloAmbient

iPhone volume increases or decreases intermittently / abruptly

We have a volume slider on the audio player in our iphone app. It streams music from our server. All is well initially until the point that some background operation happens on the iPhone.
Eg: The Mail app downloads new mails in the background and that makes a little audio sound
or
I receive a new SMS and that gives a little sound alert.
In such cases, the volume of our music player increases or decreases abruptly. The slider stays where it is, but the volume pitch changes. The only way to get where it was before is pause and play again and then the volume re-adjusts.
Any idea how to solve this issue?
Thank you in advance
Swap
Sounds like a classic Audio Session Category issue.
Check the Audio Session Programming Guide on Configuring your Audio Session.
Specifically, try to setup your application audio session towards AVAudioSessionCategoryPlayback.
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayback
error: &setCategoryError];
if (setCategoryError) { /* handle the error condition */ }

System Sound Lock

I am developing an iPhone app that translates voice to text.
The component for the Transcribe is third-party.
Until now everything worked just fine.
Today I tried playing a sound (.wav file) after making the Transcription and noticed that I cannot play anything (by AVAudio or system sound). After debugging I found out that this is happening after initing the third-party component; so I think that the component is not releasing something that belongs to the system audio.
My question is : Is there a way to force the iPhone play the sound that I want?
Have you tried setting AVAudioSession category?
NSError *err = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&err];
Maybe other category will work, for example AVAudioSessionCategoryPlayAndRecord
The best way IMO is to save AVAudioSession state (its category, for example) before using your third-party component and restore state afterwards.