Audio queue start failed

后端 未结 2 1874
孤城傲影
孤城傲影 2021-01-14 06:42

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 avaud

相关标签:
2条回答
  • 2021-01-14 07:00

    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");
          }
        }
      }
    }
    
    0 讨论(0)
  • 2021-01-14 07:23

    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

    0 讨论(0)
提交回复
热议问题