Open JimAdamsdev opened 4 years ago
did you find a solution for this. I am having the same exact problem. It changes all the audio output of my app to the ear speaker. I wonder if you found a work around to this issue. Thanks.
Have not found a work around. I did notice that if you close the app and then reopen it then all speakers
work. However, when you record it switches it back. I got pulled in a different direction. Going to get back into
this later this week. Wondered if a way exists to reset speakers after recording finishes. Let me know if you have
any luck. Thanks.
From: fliot4u notifications@github.com Sent: Tuesday, July 21, 2020 12:14 PM To: NateRickard/Plugin.AudioRecorder Plugin.AudioRecorder@noreply.github.com Cc: JimAdamsdev jim@adamstechsols.com; Author author@noreply.github.com Subject: Re: [NateRickard/Plugin.AudioRecorder] Audio for IOS is coming out of ear speaker and not main speakers. (#52)
did you find a solution for this. I am having the same exact problem. It changes all the audio output of my app to the ear speaker. I wonder if you found a work around to this issue. Thanks.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/NateRickard/Plugin.AudioRecorder/issues/52#issuecomment-661956629 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AQE5BIZONNM3CSIBZNQGL2TR4W5FTANCNFSM4OPAXMNQ .
I did found a solution or workaround.
Create an interface on your share project like this:
namespace
and create a class AudioService.cs that implements it just like this: using System; using AVFoundation; using Foundation;
namespace
public void PlaySoundThroughSpeaker()
{
var session = AVAudioSession.SharedInstance();
session.SetCategory(AVAudioSessionCategory.Playback);
session.SetActive(true);
}
public void PlaySoundThroughEarPiece()
{
var session = AVAudioSession.SharedInstance();
session.SetCategory(AVAudioSessionCategory.PlayAndRecord);
session.SetActive(true);
}
}
}
then in your event clicked do something like this: void RecordClicked(System.Object sender, System.EventArgs e) { var audioService = new AudioService(); audioService.PlaySoundThroughEarPiece(); RecordAudio(); } because before recording we have to allow the phone to use the microphone and ear speaker. and then in wherever you handle the audio file created by the recorder add this code at the end:
private void Recorder_AudioInputReceived(object sender, string audioFile) {
DisplayAlert("Notification", "Audio Message Sent Succesfully!", "Close");
var audioService = new AudioService();
audioService.PlaySoundThroughSpeaker();
}
basically we are changing from the main speakers to the ear speakers. but as I notice if we are going to record we need to set it as ear speakers for that but we can easily change it back when we are done recording. Hope it helps! Good Luck!
Thanks! 😊 My android phone has only one speaker. Have you tested to see if its also occuring on Android?
From: fliot4u notifications@github.com Sent: Tuesday, July 21, 2020 2:14 PM To: NateRickard/Plugin.AudioRecorder Plugin.AudioRecorder@noreply.github.com Cc: JimAdamsdev jim@adamstechsols.com; Author author@noreply.github.com Subject: Re: [NateRickard/Plugin.AudioRecorder] Audio for IOS is coming out of ear speaker and not main speakers. (#52)
I did found a solution or workaround. Create an interface on your share project like this: namespace .IOS { public interface IAudioService { } }
and create a class AudioService.cs that implements it just like this: using System; using AVFoundation; using Foundation;
namespace .iOS { public class AudioService : IAudioService { public AudioService() { }
public void PlaySoundThroughSpeaker()
{
var session = AVAudioSession.SharedInstance();
session.SetCategory(AVAudioSessionCategory.Playback);
session.SetActive(true);
}
public void PlaySoundThroughEarPiece()
{
var session = AVAudioSession.SharedInstance();
session.SetCategory(AVAudioSessionCategory.PlayAndRecord);
session.SetActive(true);
}
}
}
then in your event clicked do something like this: void RecordClicked(System.Object sender, System.EventArgs e) { var audioService = new AudioService(); audioService.PlaySoundThroughEarPiece(); RecordAudio(); } because before recording we have to allow the phone to use the microphone and ear speaker. and then in wherever you handle the audio file created by the recorder add this code at the end:
private void Recorder_AudioInputReceived(object sender, string audioFile) {
DisplayAlert("Notification", "Audio Message Sent Succesfully!", "Close");
var audioService = new AudioService();
audioService.PlaySoundThroughSpeaker();
}
basically we are changing from the main speakers to the ear speakers. but as I notice if we are going to record we need to set it as ear speakers for that but we can easily change it back when we are done recording. Hope it helps! Good Luck!
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/NateRickard/Plugin.AudioRecorder/issues/52#issuecomment-662024028 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AQE5BI5DCAIGPBVUHJ7GXZDR4XLHLANCNFSM4OPAXMNQ .
At least for me the android side doesn't give any issues. But in order to run that code in the shared code you can either add a try{}catch{} or put the code inside a:
var audioService = new AudioService(); audioService.PlaySoundThroughSpeaker();
because android will give you an exception when you try to initialize an audio service.
When I play audio the sound just comes out of the ear speaker for IOS. Can I do something to change this to come out of all the speakers or switch to the main speaker? Thanks in advance for your help.
Jim