-
-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Description
StopAsync() works as expected with Android, but on IOS, the first recording StopAsync() returns a null object. Subsequent recordings return a usable IAudioSource object. I've tried the Plugin.Maui.Audio.Sample and I don't see any issues with it, so it points to my code, but I do not see any problems with it.
While recording, I am able to poll audioRecorder.IsRecording and see that it is true.
Under what circumstances does StopAsync() return null? See vStopRecord() below.
I have the following methods to start/stop recording:
public async Task vStartRecord() {
if ( await CheckPermissionIsGrantedAsync<Microphone>() ) {
audioRecorder = audioManager.CreateRecorder();
if ( audioRecorder == null ) {
var toast = Toast.Make("error creating audio recorder", CommunityToolkit.Maui.Core.ToastDuration.Long, 12);
await toast.Show();
return;
}
var toast2 = Toast.Make("audio recorder can record: " + audioRecorder.CanRecordAudio, CommunityToolkit.Maui.Core.ToastDuration.Long, 12);
await toast2.Show();
var options = new AudioRecorderOptions {
Channels = ChannelType.Mono,
BitDepth = BitDepth.Pcm16bit,
Encoding = Plugin.Maui.Audio.Encoding.Wav,
SampleRate = 8000,
ThrowIfNotSupported = true,
#if IOS || MACCATALYST
Category = AVFoundation.AVAudioSessionCategory.PlayAndRecord
#endif
};
try {
await audioRecorder.StartAsync(options);
}
catch {
var toast = Toast.Make("error starting audio recorder", CommunityToolkit.Maui.Core.ToastDuration.Long, 12);
await toast.Show();
return;
}
}
else {
var toast = Toast.Make("no permission to record", CommunityToolkit.Maui.Core.ToastDuration.Long, 12);
await toast.Show();
}
}
public async Task vStopRecord() {
if ( audioRecorder != null ) {
audioSource = await audioRecorder.StopAsync();
if ( audioSource != null ) {
var toast = Toast.Make("no audio recorded", CommunityToolkit.Maui.Core.ToastDuration.Long, 12);
await toast.Show();
}
}
}
Copilot
Metadata
Metadata
Assignees
Labels
No labels