Я пытаюсь обрабатывать прерывание потоковой передачи аудио, когда пользователь получает вызов, аудио паузы, тогда он должен возобновиться, когда вызов будет завершен.Почему моя ссылка класса AVPlayer в AppDelegate возвращает нуль?
Но моя ссылка на мой класс MyAVPlayer
возвращает нуль, в этих строках кода [myAVPlayer pauseAACStreaming:self];
и [myAVPlayer playACCStreaming:self];
показано ниже.
Почему это nil
, так как у меня есть звук? Есть ли лучший способ сделать это?
у меня в AppDelegate.ha ссылки на пользовательский класс MyAVPlayer, например, так:
@class MyAVPlayer;
@interface AppDelegate : NSObject <UIApplicationDelegate>
{
MyAVPlayer *myAVPlayer;
}
@property (nonatomic, retain) MyAVPlayer *myAVPlayer;
Тогда в AppDelegate.m у меня есть:
#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];
}
}
Это не позволит мне используйте свойство myAVPlayer внутри функции Void AudioSessionInterruptionListenerCallBack (void * inClientData, UInt32 inInterruptionState). – Winston
Я изменил свой код на основе вашего предложения, и теперь он работает. Благодаря! – Winston