I’m trying to handle audio streaming interruption, when the user receives a call the audio pauses, then it should resume when the call is finished.
But my reference to my MyAVPlayer class returns nil, in these lines of code [myAVPlayer pauseAACStreaming:self]; and [myAVPlayer playACCStreaming:self]; shown below.
Why is it nil, since I’ve the audio playing? Is there a better way to do it?
I have in my AppDelegate.h a reference to a custom class MyAVPlayer, like so:
@class MyAVPlayer;
@interface AppDelegate : NSObject <UIApplicationDelegate>
{
MyAVPlayer *myAVPlayer;
}
@property (nonatomic, retain) MyAVPlayer *myAVPlayer;
Then, in AppDelegate.m I have:
#import "MyAVPlayer.h"
void AudioSessionInterruptionListenerCallBack(void *inClientData, UInt32 inInterruptionState);
@implementation AppDelegate
@synthesize myAVPlayer;
void AudioSessionInterruptionListenerCallBack (void *inClientData, UInt32 inInterruptionState)
{
NSLog(@"Audio session interruption");
MyAVPlayer* streamer = (MyAVPlayer *)inClientData;
[streamer handleInterruptionChangeToState:inInterruptionState];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
AudioSessionInitialize (
NULL,
NULL,
AudioSessionInterruptionListenerCallBack,
self
);
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
AudioSessionInitialize (
NULL,
NULL,
AudioSessionInterruptionListenerCallBack,
self
);
}
- (void)handleInterruptionChangeToState:(AudioQueuePropertyID)inInterruptionState
{
NSLog(@"handleInterruptionChangeToState");
if (inInterruptionState == kAudioSessionBeginInterruption)
{
[myAVPlayer pauseAACStreaming:self];
}
else if (inInterruptionState == kAudioSessionEndInterruption)
{
AudioSessionSetActive( true );
[myAVPlayer playACCStreaming:self];
}
}
The problem is that you have a property called
myAVPlayer, but the variable you are assigning using the line:Instead, you should use: