title: Audio not playing until moving the camera away from Qr code - iOS
body: <p>I am new to <code>iOS</code> <code>development</code> and I am developing an app in which I want to play some audios when the <code>QR code</code> gets detected. I am able to detect the <code>QR code</code> and also play the audios but the thing is the audio-only plays when I move the camera away from <code>QR code</code>. So, if I am pointing the camera towards <code>QR code</code> it does not play the audio but as soon as I move the camera (i.e. no <code>QR code</code> is getting detected) the audio starts playing. I don't want this behavior I want audio to play as soon as <code>QR code</code> gets detected. Any suggestion would be great as I have just started <code>iOS</code> <code>development</code> 2 3 days back. Thanks.</p>
  
  <pre><code>-(void)captureOutput:(AVCaptureOutput *)captureOutput
  didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection(AVCaptureConnection *)connection{
  
  
  
  NSString *detected=@"";
  
  
  
  if (metadataObjects != nil &amp;&amp; [metadataObjects count] &gt; 0) {
  
  
  
      AVMetadataMachineReadableCodeObject *metadataObj = [metadataObjects objectAtIndex:0];
  
  
  
      if ([[metadataObj type] isEqualToString:AVMetadataObjectTypeQRCode]) {
  
  
          detected=[NSString stringWithString:[metadataObj stringValue]];
  
          NSString *path =  [[NSBundle mainBundle] pathForResource:@"cbp"  ofType:@"mp3"];
  
          NSURL *url = [NSURL URLWithString:path];
  
  
  
          _audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:NULL];
  
  
          [_audioPlayer play];
  
  
      }
  
  
  
  }
  </code></pre>
  
  <p>}</p>