title: How to stop play sound if silent mode is turned on
body: <p>My code:</p>
  
  <pre><code>NSString *soundName = [[NSBundle mainBundle] pathForResource:@"music" ofType:@"mp3"];
  NSURL *soundURL = [NSURL fileURLWithPath:soundName];
  NSError *error = [[NSError alloc] init];
  self.backgroundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&amp;error];
  
  if (self.backgroundPlayer == nil) {
      NSLog(@"error = %@",[error description]);
  } else {
      [self.backgroundPlayer setDelegate:self];
      [self.backgroundPlayer setNumberOfLoops:HUGE_VAL];
      [self.backgroundPlayer setVolume:0.5f];
      [self.backgroundPlayer prepareToPlay];
      if ([self.backgroundPlayer prepareToPlay]) {
          if ([self.backgroundPlayer play]) {
              NSLog(@"playing");
          }
      } else {
          NSLog(@"error!");
      }
  }
  </code></pre>
  
  <p>When I switch iPhone to silent mode sound still plays. How can I solve this problem?</p>