Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

后台播放音乐,来电话,挂断电话就崩溃了 #45

Open
jandyway opened this issue Jul 1, 2014 · 1 comment
Open

后台播放音乐,来电话,挂断电话就崩溃了 #45

jandyway opened this issue Jul 1, 2014 · 1 comment

Comments

@jandyway
Copy link

jandyway commented Jul 1, 2014

崩溃停在了DOUAudioEventLoop.m文件的- (BOOL)_handleEvent:(event_type)event withStreamer:(DOUAudioStreamer **)streamer方法中的:
NSAssert(status == noErr, @"failed to activate audio session");
这个断言失败,status 不等于noErr, 打印出来了failed to activate audio session

@johnlui
Copy link

johnlui commented Jul 1, 2016

原因很简单:http://stackoverflow.com/a/6999245/4404288

解决办法如下:

将以下代码放到 if (status == noErr) { 之外:

[_renderer setInterrupted:NO];

        if (*streamer != nil &&
            [*streamer status] == DOUAudioStreamerPaused &&
            [*streamer isPausedByInterruption]) {
          [*streamer setPausedByInterruption:NO];
          [self performSelector:@selector(play) onThread:[NSThread mainThread] withObject:nil waitUntilDone:NO];
        }

然后将如下代码全部注释掉:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
      OSStatus status;
      status = AudioSessionSetActive(TRUE);
      NSAssert(status == noErr, @"failed to activate audio session");
#pragma clang diagnostic pop
      if (status == noErr) {

      }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants