Toggle audio in speaker to ear-speaker and ear-speaker to speaker

本小妞迷上赌 提交于 2019-12-11 17:01:39

问题


We are using third party Audio/Video SDK in our Xamarin.Forms.Android project. Now problem is that by default audio comes in speaker mode, instead of ear-speaker. I was tried to search solution in internet and found below code to set audio in ear-speaker and speaker. After implement below code audio off in speaker but not able to listen via ear-speaker, if I set SpeakerphoneOn=true then I can listen via Speakerphone but if I set SpeakerphoneOn=false then I can't list via ear-speaker.

Additional point, Mode value is always comes "InCommunication" even after change to InCall or any other mode.

I have set below permission too in my Xamarin project. Permission:

var audioManager = (Android.Media.AudioManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.AudioService);

audioManager.SpeakerphoneOn = !audioManager.SpeakerphoneOn;

回答1:


Check when mode is ear-speaker , the volume value whether is 0 .The volume of their two modes is controlled separately.

var audioManager = (Android.Media.AudioManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.AudioService);
audioManager.Mode = Mode.InCommunication;
audioManager.SpeakerphoneOn = false;
audioManager.SetStreamVolume(Stream.Music, audioManager.GetStreamMaxVolume(Stream.Music), VolumeNotificationFlags.ShowUi);


来源:https://stackoverflow.com/questions/55649921/toggle-audio-in-speaker-to-ear-speaker-and-ear-speaker-to-speaker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!