NateRickard / Plugin.AudioRecorder

Audio Recorder plugin for Xamarin and Windows
MIT License
164 stars 68 forks source link

Audio no longer captured on iOS #38

Closed tekmun closed 4 years ago

tekmun commented 5 years ago

Hi,

With iOS 12.2, audio is no longer captured. Same code but the AudioInputReceived event is not called.

NateRickard commented 5 years ago

Is anything logged when you begin recording? Wondering there's an exception happening that's preventing things from getting started.

tekmun commented 5 years ago

The issue is solved by adding the suggested ConfigureAVAudioSession in iOS AppDelegate.cs.

npostma commented 4 years ago

I've noticed a simulair issue for iOS. After starting recording the recorder never sets recording to true. I use the plugin.MediaManager also. No issues with android though.

npostma commented 4 years ago

' the suggested ConfigureAVAudioSession in iOS AppDelegate.cs.' does not seem to work with iOS 13.1.2 I am getting the error 'audioQueue.Start() returned non-OK status: GeneralParamError ' again. I've tried adding:

 var audioSession = AVAudioSession.SharedInstance();

            // If AVAudioSessionCategoryOptions.MixWithOthers option is cleared, activating your session interrupts other audio sessions. If this option is set, your app's audio is mixed with audio playing in background apps (such as the Music app).
            var audioError = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord, AVAudioSessionCategoryOptions.MixWithOthers);

and withoud the AVAudioSessionCategoryOptions.

Edit:

Some additional info: iPhone11 version 13.1.2, iOS,

audioQueue.Start() returned non-OK status: GeneralParamError 

at Plugin.AudioRecorder.AudioStream+<>c.<Start>b__24_2 (AudioToolbox.AudioQueueStatus status) [0x00000] in C:\Repos\libs\Plugin.AudioRecorder\Plugin.AudioRecorder.iOS\AudioStream.cs:102    
at Plugin.AudioRecorder.AudioStream.BufferOperation (System.Func`1[TResult] bufferFn, System.Action successAction, System.Action`1[T] failAction) [0x00017] in C:\Repos\libs\Plugin.AudioRecorder\Plugin.AudioRecorder.iOS\AudioStream.cs:80    
at Plugin.AudioRecorder.AudioStream.Start () [0x0005c] in C:\Repos\libs\Plugin.AudioRecorder\Plugin.AudioRecorder.iOS\AudioStream.cs:112    
at Plugin.AudioRecorder.WaveRecorder.StartRecorder (Plugin.AudioRecorder.IAudioStream stream, System.String filePath) [0x00198] in C:\Repos\libs\Plugin.AudioRecorder\Plugin.AudioRecorder.Shared\WaveRecorder.cs:59    
at Plugin.AudioRecorder.AudioRecorderService.StartRecording () [0x000bc] in C:\Repos\libs\Plugin.AudioRecorder\Plugin.AudioRecorder.Shared\AudioRecorderService.cs:112    
at App.Views.Page.RecordAudio () [0x000e8] in <c7574cddbf3c4ef8a723d1626fd5fe09>:0
npostma commented 4 years ago

Implemented a DependencyService to change the category back and forth. That worked like a charm. I red that this was not necessarily for version 1.0.1 and beyond. But it seems that this is necessarily (again?)

(adding this in the AppDelegate.cs is not sufficient)

klogeaage commented 4 years ago

I also had problems with the default setup of the plugin on iOS 13.1.2 and made a DependencyService to workaround it. That worked, but after further reading the documentation and the source code, I also found that just specifying the category for BOTH play and record in the AppDelegate.cs worked equally well, i.e.:

// Make audio behave sensible to our needs for both play and record AudioPlayer.RequestAVAudioSessionCategory(AVAudioSessionCategory.Playback); AudioRecorderService.RequestAVAudioSessionCategory(AVAudioSessionCategory.Record);

This also solves another issue: by default, it will playback sound using the small upper speaker for telephone conversations, making it almost inaudible unless you put the phone up to your ear. But explicitly specifying PlayBack automatically switches it to the larger speakers at the bottom, unless you attach headphones, which is precisely what you want.

So maybe the default settings should be like this? Or at least update the iOS section of the ReadMe.md file to reflect that this is a necessary configuration for most usages.

npostma commented 4 years ago

I've used BOTH too. But the mediamanager plugin resets it. So you will still need to set it back and forth.