您的位置:首页 > 移动开发 > IOS开发

AudioStreamer电话时crash

2014-01-10 14:57 1211 查看
crash时定位在AudioStreamer:
staticvoid ASAudioSessionInterruptionListener(void *inClientData,UInt32
inInterruptionState)
{
AudioStreamer* streamer = (AudioStreamer *)inClientData;
[streamerhandleInterruptionChangeToState:inInterruptionState];
}

我们可以换一种实现方式:

AudioSessionInitialize (

NULL,                         // 'NULL' to use the default (main) run loop

NULL,                         // 'NULL' to use the default run loop mode

ASAudioSessionInterruptionListener, // a reference to your interruption callback

self                      // data to pass to your interruption listener callback
);

替换成

AVAudioSession *mySession = [AVAudioSessionsharedInstance];

        

        // Specify that this object is the delegate of the audio session, so that

        //    this object's endInterruption method will be invoked when needed.
       [mySession
setDelegate:self];

且实现以下方法:

- (void) beginInterruption {

    
   if ([self
isPlaying]) {
        [selfpause];

        

        pausedByInterruption =YES;
    }

    
}

NSError *activationError =nil;

- (void) endInterruption {

    

    AudioSessionSetActive(true );

    

    if ([selfisPaused]
&&pausedByInterruption) {

        [selfpause];
// this is actually resume

        

        pausedByInterruption =NO;
// this is redundant
    }

    
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息