pete
pete

Reputation: 3050

Audio from UIWebView causes problems with AVAudioRecorder

Using a storyboard for an iPad app, I have a viewController that presents a UIWebView , AVAudioPlayer and AVAudioRecorder. All three instances are working with no problem. The function of the recorder is to make voice comments regarding various websites that have been loaded into the webView.

The problem occurs if the user listens to audio in the webView eg YouTube. Without trying to record audio from the web, the AVAudioRecorder from that point on no longer records. There are no errors and the app continues to run as normal but all recorded data has a zero file size. Even if I remove the webView from view or set the webView = nil; The AVAudioRecorder seems to work but again, all recorded data is zero.

Upvotes: 1

Views: 911

Answers (1)

pete
pete

Reputation: 3050

after many hours of research and work heres the answer to my own question - I hope it helps someone.

   // This enables both record and play at the same time
AVAudioSession *myAudioSession = [AVAudioSession sharedInstance];
[myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[myAudioSession setActive:YES error:nil];


// Use the default sound system and audio sound level. 
UInt32 doChangeDefaultRoute = 1;
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute);

Upvotes: 1

Related Questions