Set audio session to media in IOS.
I'm trying to make an app that plays music and I want to to continue playing when the phone is set to silent or if the phone is put to sleep. (these may need two separate solutions.) The main important thing is to get it to play sounds while the phone is on silent just link music plays on the iPhone. I think the answer may be something to do with Audio Sessions. I found this article, but couldn't figure out how to make it work. (might be that this technique doesn't work anymore) http://forum.unity3d.com/threads/setting-mediaplayback-audio-session-category.206958/
They said to do something like this AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
if (![session setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionMixWithOthers
error:&setCategoryError]) {
// handle error
}
or OSStatus propertySetError = 0; UInt32 allowMixing = true;
propertySetError = AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryMixWithOthers, // 1
sizeof (allowMixing), // 2
&allowMixing // 3
);
Though I wasn't sure where to put this code or what else would need to be done. Thanks for the help
Answer by 265lutab · Jul 20, 2016 at 11:23 PM
One of the problems I'm having right now which I'm hoping this will fix is a bug where I can only hear sound from headphones. I think that the tester might have the game volume all the way down. I'm not sure, but I was hoping that this would fix the problem.
Answer by LisaDreams · Jul 20, 2016 at 11:33 PM
Hi, just to be clear you want to play sounds even when the user sets the sounds to off? I'm asking, because it seems to me that if the user has their sounds off they wouldn't want to hear any sounds.
If you want to have your sounds continue to play when the lock screen comes on, you can add an audio key in the UIBackgroundModes in the plist that will let the audio continue to play.
Good luck!!
When you play music or videos it will make sound even if you have it switched to silent. I did solve the problem. I used the plugin from the post I mentioned. I had not been using it correctly at first, but it's working now.
Your answer
Follow this Question
Related Questions
Designate unity audio as music. Play in background and when phone is on silent. IOS 0 Answers
Music Player 0 Answers
iOS Audio Skipping Tracks 0 Answers