Hi…,
my OF8.0 iPhone app doesn’t play sound anymore after an iPhone call.
Any ideas?
Thanks
Mike
Hi…,
my OF8.0 iPhone app doesn’t play sound anymore after an iPhone call.
Any ideas?
Thanks
Mike
I ran some examples in ios 8.1. it looks like openframeworks automatically terminates apps when app enters background state. In the info plist change “Application does not run in background” to NO. That might work.
That being said i am not seeing any code to handle audio when apps move to a background state. Normally you shoud stop the AUGraph, and then set the Audio Session to inactive.
[self stopGraph];
[[AVAudioSession sharedInstance] setActive:NO error:nil];
So it seems there is a bug. Maybe someone who knows more can tell you whats up.
Hi Ahbee,
thank you for your information. I had already set “Application does not run in background” to NO, but with no help. OF0.8.1 doesn’t run here at the moment, because it just sees to run with Apple IOS SDK 6.1, which I can’t install on my MAC.
Thanks
Mike
This maybe of help? http://stackoverflow.com/questions/15845064/augraph-stops-running-after-phone-call-interrupt-in-ios .It says there is a bug in ios 6. But even in ios 7 openframeworks is not handling interruptions
Hi Ahbee,
thank you very much, I will take a closer look.
Have a good time
Mike
Hi @Ahbee,
I have read the stackoverflow article, and I played a little bit around with the following methods, but I have no clue how to get this to run. I’ve tried to copy your code
[self stopGraph];
[[AVAudioSession sharedInstance] setActive:NO error:nil];
in the applicationDidEnterBackground method, but stopGraph and sharedInstance is unkown. Sorry, I have no cocoa and objective c experience.
-(void)applicationDidEnterBackground:(UIApplication *)application
{
[super applicationDidEnterBackground:application];
NSLog(@"DidEnterBackground");
}
-(void)applicationDidBecomeActive:(UIApplication *)application
{
[super applicationDidBecomeActive:application];
NSLog(@"DidBecomeActive");
}
Perhaps you have more code for me.
Thanks
Mike
That was just pseudocode so it wont work. AUGraph is the structure that is used to organize audio processing. Can you you give more details on what you are trying to do? Are you using ofSoundStream or ofSoundPlayer? If you upgrade to ios 7 do you still have the problem? Does pressing the home button, then pressing the app button also stop sound?
Dear Ahbee,
I use ofxOpenALSoundPlayer. When I get a call or start Siri, I get no sound anymore in ios 6 and ios 7.1. I have to restart to get sounds again. Pressing home to pause, doesn’t stop sounds.
Does this help?
Thanks
Mike
I ran the soundPlayer example on my phone. The sound still continues even after the phone call and siri.
Insted of ofxOpenALSoundPlayer, can you just use ofSoundPlayer? I looked at the code for ofxOpenALSoundPlayer, and it does not handle interruptions. It will be hard to add code for interruptions without hacking openframeworks because openframeworks does not give access to the the openAl context.
Hi Ahbee,
yes, you are right, I’ve found out now that ofSoundPlayer and AVSoundPlayer work here too, whithout this problem. Only the ofxOpenALSoundPlayer stops playing sound after call/siri/timer/etc. interruption.
ofSoundPlayer and AVSoundPlayer are no option for me, I have to use ofxOpenALSoundPlayer, because only ofxOpenALSoundPlayer doesn’t drop my app frame rate, see here
What to do, hack ofxOpenALSoundPlayer? Perhaps @admsyn knows more.
Thanks
Mike
If you’re getting a reduced frame rate using the other two sound players, investigating that would probably be helpful. Is the sound file you’re loading a big file? Does it have to be? If you’re loading a giant file into RAM then that’d probably be the cause of the frame drop.
Judging from your other post, it looks like a tiny clip you’re using as a metronome? You should be able to play a small file just fine, maybe try it not as a .caf? Also if you’re using it as a metronome, building off of e.g. ofGetElapsedTimeMillis()
would be way more reliable than counting frames.
Yes you’ll probably have to “hack” ofxOpenALSoundPlayer if you want to make it respond to interruptions. You can look at the SoundStream implementation to see it being used there, though google might be more straightforward.
Hi Admsyn,
the frame rate drops shortly, when I start to play ofSoundPlayer and AVSoundPlayer sound objects, when they are playing there are no drops/reduction. I think this is related, that I can’t use multiplay with ofSoundPlayer and AVSoundPlayer, only with ofxOpenALSoundPlayer. No, I play very very small CAF-files, about 20 KByte(!) big.
The frame rate drop is obvious by playing smallest CAF-files, I think checking millis will not help.
Hacking/Debugging ofxOpenALSoundPlayer will become hard for me, I am an objective-c/cocoa dummy.
Thanks
Michael
You can hack it like this.
Step 1 - add this function to SoundEngine.h
ALCcontext* SoundEngine_GetOpenALContext();
step 2 - make this new function a friend to OpenALObject in SoundEngine.cpp
private:
Float32 mOutputRate;
Float32 mGain;
ALCcontext* mContext;
ALCdevice* mDevice;
SoundEngineEffectMap* mEffectsMap;
ALuint mSourceID[MAX_SOURCES];
bool mSourcePrimed[MAX_SOURCES];
friend ALCcontext* SoundEngine_GetOpenALContext();
step 3 - define this function in SoundEngine.cpp
ALCcontext* SoundEngine_GetOpenALContext(){
return sOpenALObject->mContext;
}
step 4 - create an objectiveC class call InterruptionHandler, make sure you use .mm instead of .m
InterruptionHandler.h looks like this
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
@interface InterruptionHandler : NSObject <AVAudioSessionDelegate>
@end
InterruptionHandler.mm looks like this
#import "InterruptionHandler.h"
#import "SoundEngine.h"
@implementation InterruptionHandler
-(void)beginInterruption{
ALCcontext* context = SoundEngine_GetOpenALContext();
alcMakeContextCurrent(NULL);
alcSuspendContext(context);
}
-(void)endInterruption{
ALCcontext* context = SoundEngine_GetOpenALContext();
alcMakeContextCurrent(context);
alcProcessContext(context);
}
@end
step 5 - import InterruptionHandler in ofApp.h
#import "InterruptionHandler.h"
step 6 - create a member in ofApp.h
InterruptionHandler *interruputionHandler;
step 7 - in ofApp.cpp put this your setup function before anything else;
interruputionHandler = [InterruptionHandler new];
[[AVAudioSession sharedInstance] setDelegate:interruputionHandler];
Let me know if you have any trouble.
Dear Ahbee,
wow, thank you so much, your detailed explanations are great and worked here very well, no more sound silence here in iOS 5.1/6.1 and 7.1 (tested in of 0.8.1) after interruptions with ofxOpenALSoundPlayer.
Great, thank you again
Michael
P.S.: And thank you also to Admsyn, and sorry for my bothersome questions.
@Abhee, this looks very useful, but i am facing issue regarding C++ file, could you help me, i am getting errors in c++ file.
im facing issue regarding “SoundEngineEffectMap” unknown type name
that looks like you need a forward declaration somewhere? I am sure apis were changed since this post is very old
what file are you getting error?
usually you can fix that by putting class SoundEngineMap;
instead of including the .h file
@Ahbee thanks so much for your resply!, but i am audio session for VOIP call in my app. suppose, i made a call through my app, after established the call, my app came to background, suppose if i got native call to device, after native call disconnectes, if my app came to foreground, that time audio is audible. This is the issue, i am facing!
this issue in this thread is specifically with ofxOpenALSoundPlayer, you dont seem to be using that.
I have not programmed ios in a while so I kind of forgot how the audio api(it probably changed a lot since I last programmed also)
The only advice I can give is to read The audio session programming guide