Audio queue start failed

2020-03-25 11:44发布

I'm developing a project which has both audio streaming and playing audio from file. For audio streaming i'm using AudioStreamer and for playing from file i'm using avaudioplayer. Both streaming and playing works perfectly as long as the app is not interrupted by a phone call or sms. But when a call/sms comes after dismissing the call when i try to restart streaming i'm getting the error "Audio queue start failed" . This happens only when i have used avaudioplayer at least once and after that used streaming. When the avaudioplayer obeject is not created , in this scenario the there is no problem with resuming streaming after dismissing the call. My guess is that some thing is wrong with audioqueue.

Help is very much appreciated.

Update:

The code that I'm currently using is given below

void interruptionListenerCallback (void *inUserData, UInt32 interruptionState) {

    // This callback, being outside the implementation block, needs a reference 
    //to the AudioPlayer object
    AudioStreamer *player = (AudioStreamer *)[streamerArray objectAtIndex:0];

    if (interruptionState == kAudioSessionBeginInterruption) {
        NSLog(@"kAudioSessionBeginInterruption 1");

            [player pause];
            interruptedOnPlayback = YES;


    }       else if (interruptionState == kAudioSessionEndInterruption) {
            NSLog(@"kAudioSessionEndInterruption 2");
              AudioSessionSetActive( true );


        [player start];
        interruptedOnPlayback = NO;

    }
}

as you could see i'm using AudioSessionSetActive(true) it works fine as long as the avaudioplayer object is not created . The problem occurs only when i'm using the streamer after creating the Avaudioplayer object and if the app gets interrupted by a phone call
or sms i get the error Audio queue start failed?!

标签: iphone
2条回答
太酷不给撩
2楼-- · 2020-03-25 12:17

I had the same problem, in more detail the error message was "hwiu" (hardware in use) or 1752656245. But I was using the MPMoviePlayerController before starting the audioStreamer. I only had to stop the MPMoviePlayerController ([moviePlayer stop]) before releasing it in the moviePlayBackDidFinish method. the stop should release some hardware componants.

I hope it helps

查看更多
家丑人穷心不美
3楼-- · 2020-03-25 12:23

You need to make the audio session active yourself after the interruption.

I don't know AVAudioPlayer, but if you were using the audio queue services directly, you could have something like this as your interruption handler:

void interruptionListener(void * inClientData, UInt32 inInterruptionState) {
  if (inInterruptionState == kAudioSessionEndInterruption) {
    OSStatus rc = AudioSessionSetActive(true);
    if (rc) {
      NSLog(@"AudioSessionSetActive(true) returned %d", rc);
    }
  }
}

and pass that into your AudioSessionInitialize() call.

You can restart the session lazily, too:

-(void)startPlaying {
  OSStatus rc = AudioQueueStart(queue, NULL);
  if (rc) {
    NSLog(@"startPlaying AudioQueueStart returned %d.", rc);

    if (rc == kAudioSessionNotActiveError) {
      rc = AudioSessionSetActive(true);
      if (rc) {
        NSLog(@"startPlaying - AudioSessionSetActive(true) returned %.d", rc);
      } else {
        NSLog(@"startPlaying - restarted Audio Session");
      }
    }
  }
}
查看更多
登录 后发表回答