I am trying to play a short music but when iPod is playing and lunch the application music goes off ! how can I prevent this situation ? I am using AVAudioPlayer to play sound .
thanks
For AudioToolBox and and short effect sounds you can use kAudioSessionCategory
AudioSessionInitialize(NULL, NULL, NULL, self);
UInt32 category = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
AudioSessionSetActive(YES);
hopes can help ;)
Related
I want to hear a recorded file when my iphone is on silent mode. For that I have implemented the following code.
-(void)viewWillAppear:(BOOL)animated{
AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
// Allow playback even if Ring/Silent switch is on mute
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory),&sessionCategory);
}
I am unable to hear high pitched sound in iphone and in my ipad the sound effect button is enabled even when I am not able to hear any sound.
Before implementing above code I was able to hear recorded file.
If you have any idea or code then share it
thanx in advance...
I'm developing a teaching app playing video animations with no sound.
I would like to prevent the movie player from stopping other audio sessions (such as the iPod) when the video is launched.
Is there any way to indicate the iOS the video has no audio or play in mute mode?
Thanks in advance for your help!
You can always detect if the music is playing and and resume it right way after the movie started playing.
Detecting player state
[MPMusicPlayerController iPodMusicPlayer] playbackState]
Resume
[[MPMusicPlayerController iPodMusicPlayer] play];
I think maybe something like this
UInt32 allowMixing = YES;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing);
AudioSessionSetActive(YES);
should do the the trick.
Keep in mind, you'll need to add the AudioToolbox library to your application, and add:
#import <AudioToolbox/AudioToolbox.h>
to your classes imports in order to use the above code.
It should allow your app's sounds to mix with the other app's sounds in the background. In this case, since your app is silent, it will just allow background sounds to keep playing.
Hope it helps!
So I've already gone through most of the relevant question on SO that I could find, yet I still can't get my audio playing while silent. I believe that it's probably a small error I'm making.
I'm trying to play a small alert sound. This is the code in my viewDidLoad method :
AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
And here is the method I call when I need to play an audio clip
-(void)playAudioClip:(CFStringRef)clip{
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFile = CFBundleCopyResourceURL(mainBundle, clip, CFSTR("wav"), NULL);
//Supposed to make sound playable even when silent right?
UInt32 soundType = kAudioSessionCategory_MediaPlayback;
UInt32 soundID;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(soundType), &soundType);
AudioServicesCreateSystemSoundID(soundFile, &soundID);
AudioServicesPlaySystmSound(soundID);
}
I got most of this off SO and confirmed it in the Apple programming guides. I have already tried combining the Uint32 for both uses but this didn't do anything either, still no play in locked/silent mode. Any ideas?
System sounds do not play while in silent mode. (As the name would suggest) If you need to play audio while silent you need to use a different method like a media player or other audio method. Look at Apple's examples for playing music.
I'm trying to record a video while the iPhone playback an audio track.
as far as i tried, whenever I simulataniously record and play - the camera get stuck.
I went over the AVFoundation PG But I could not find a specific answer.
Is it a matter of digging into this framework?
Is it a matter of threading and multitasking?
thanks
I record both audio and video while playing audio. However, in my setup I am using CoreAudio for audio and AVFoundation for video. You may want to setup the audio session to handle recording and playback. e.g.
AudioSessionInitialize(NULL, NULL, NULL, self);
UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), &audioCategory);
AudioSessionSetActive(YES);
I'm using the following Audio Session in my app delegate:
AudioSessionInitialize(NULL, NULL, NULL, self);
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
AudioSessionSetActive(true);
I want the user to be able to play iPod music and use my app at the same time, which is great and works fine... my app bows out and allows the iPod music to play.
The issue I'm having is... after the user exits my app, goes into the iPod app and pauses, when they come back into my app, none of my sounds work. It's like it still thinks the iPod session is active, even though it isn't playing any music!
I basically just want to re-activate my audio session after iPod music has been paused. As it stands, after I've ever played music via the iPod app, I am totally unable to get my app's sounds back unless I recompile. :( Anyone have any ideas?
Edit: I forgot to mention I'm using a basic implementation of the AVAudioPlayer class to play my app's audio.
Thanks!
Okay just thought I'd keep everyone posted in case it helps someone else... what I did was probably kind of hackish, but seems to do the trick!
UInt32 isPlaying;
UInt32 propertySize = sizeof(isPlaying);
OSStatus status;
// check to see if their iPod music is playing
status = AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying, &propertySize, &isPlaying);
// set the session category accordingly
if(!isPlaying) {
NSLog(#"...SoloAmbientSound");
UInt32 sessionCategory = kAudioSessionCategory_SoloAmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
}else{
NSLog(#"...AmbientSound");
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
}