0

I am building a xamarin android app using the XamarinMediaManager. The control for now contains a placeholder for the Mute functionality but it isn't implemented yet:

CrossMediaManager.Current.VolumeManager.Mute = true;
//this doesn't work, even on the develop branch

I am not sure how else i could implement that, I've tried implementing that using the way suggested in this answer, but most of the code seems to be deprecated in xamarin.

Any help would be appreciated.

  • well simply find the latest version of it then – FreakyAli Apr 28 '18 at 20:13
  • The latest version doesn't implement it yet –  Apr 28 '18 at 20:23
  • what do you mean by does not implement it yet – FreakyAli Apr 28 '18 at 20:28
  • I mean that there is only a placeholder, you can interrogate the Mute property but there is no actual code added to the library to handle the actual Mute operation : https://github.com/martijn00/XamarinMediaManager/issues/181 –  Apr 28 '18 at 20:30
  • So you trying to do it in Xamarin forms and u have problems because mute doesnt work if i am right – FreakyAli Apr 28 '18 at 20:35
  • No, actually i am on Xamarin.Android, i am looking to implement that or at least find a way to mute the sound for the app, a code snippet to mute the sound for an app would be appreciated, i've tried doing it this way : https://stackoverflow.com/questions/36441473/how-do-i-mute-all-sounds-of-my-application?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa but couldn't get it to work –  Apr 28 '18 at 20:38
  • Which of these answers did you try to use – FreakyAli Apr 28 '18 at 20:40
  • Most of them, the first answer uses a SetStreamMute which is now deprecated, and i can't get the other answers to work for the current app ! –  Apr 28 '18 at 20:47
  • Try this : https://stackoverflow.com/questions/12353629/how-to-turn-off-all-sounds-on-android – FreakyAli Apr 28 '18 at 20:54

1 Answers1

0

You can use approuce with AudioManager.SetStreamVolume

All you need is chose sound chanel and set it to 0.

var audioManager = (AudioManager)getContext.GetSystemService(Context.AudioService);
var mute = 0;
audioManager.SetStreamVolume(Stream.Music, mute, 0);

If you need to use prev sound value just save it with

var musicOrigVol = audioManager.GetStreamVolume(Stream.Music)

One more thing getContext returns my MainActivit

Dmitry Zinoviev
  • 588
  • 1
  • 6
  • 20