title: The volume of AVAudioPlayer is not as same as the system volume
body: <p>I use AVAudioPlayer to play sound, but sometimes the volume becomes very low, and not as same as the system volume. When I change the system volume by press the volume button, it becomes normal. How does it happen?</p>
  
  <p>the code is below:</p>
  
  <pre><code>- (void)prepareAudioSession {
      AVAudioSession *session = [AVAudioSession sharedInstance];
      NSError *setCategoryError = nil;
      if (![session setCategory:AVAudioSessionCategoryPlayback
                withOptions:AVAudioSessionCategoryOptionMixWithOthers
                      error:&amp;setCategoryError]) {
          // handle error
      }
  
      AVAudioSession *audioSession = [AVAudioSession sharedInstance];
      NSError *error = nil;
      BOOL result = [audioSession setActive:YES withOptions:0 error:&amp;error];
  
      if (!result &amp;&amp; error) {
          // deal with the error
      }
  }
  
  - (void)playWithAudioPath:(NSString *)path {
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
      NSError *error;
      NSURL *audioFileURL = [NSURL fileURLWithPath:path];
      self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:&amp;error];
  
      audioPlayer.delegate = self;
  
      if (error == nil) {
  
          [self prepareAudioSession];
  
          [audioPlayer setCurrentTime:0];
          [audioPlayer play];
      }
      else {
          NSLog(@"%@", error.description);
      }
  });}
  </code></pre>