0

I have created an MP3 player in a Xamarin project, and it plays great. I have added the ability to adjust the Pitch and Speed, but I cannot get the Reverb effect to take to my MediaPlayer.

I have found various examples in Kotlin and Java of the code required to create both PresetReverb and EnvironmentalReverb methods to achieve this.

While my C# code runs and produces no errors, the Reverb effect will not apply using either method. I am new to Xamarin and Android, so I am hoping to get some help.

Here is my code.

MediaPlayer _mediaPlayer = new MediaPlayer();

AssetFileDescriptor fd = global::Android.App.Application.Context.Assets.OpenFd(fileName);

#region REVERB

PresetReverb presetReverb = new PresetReverb(1, 0); // was set to _mediaPlayer.AudioSessionId
presetReverb.Preset = PresetReverb.PresetLargeroom;
presetReverb.SetEnabled(true);
_mediaPlayer.AttachAuxEffect(presetReverb.Id);
_mediaPlayer.SetAuxEffectSendLevel(1.0f);

#endregion

_mediaPlayer.SetDataSource(fd.FileDescriptor, fd.StartOffset, fd.Length);
_mediaPlayer.Prepare();
_mediaPlayer.Start();

Any ideas/advice would be greatly appreciated.

anthony_s
  • 137
  • 2
  • 11
  • What does the ` the Reverb just will not apply using either method` mean? – Wendy Zang - MSFT Mar 22 '21 at 06:26
  • There are two ways to apply Reverb to the MediaPlayer. You can use "PresetReverb" to use any of the presets, i.e.(small room, large room, etc.) or you can IGNORE PresetReverb, and use "EnvironmentalReverb" parameters which allows you to customize the reverb on your own, (DecayHFRatio = (short)1000, DecayTime = 1000, Density = (short)1000,) etc. – anthony_s Mar 22 '21 at 17:00
  • To summarize, neither method adds a reverb effect to the audio. – anthony_s Mar 22 '21 at 17:12
  • 1
    You could try Audio session 0 instead of the `AudioSessionId`. The links below would be helpful. https://stackoverflow.com/questions/61775727/using-android-presetreverb-on-audiotrack https://stackoverflow.com/questions/16130380/mediaplayer-reverb-is-not-working – Wendy Zang - MSFT Mar 23 '21 at 08:22
  • This strange, but it is working now. It's just super weak, and a low sounding effect. But I definitely can hear the residual delay/distance in the reverb when I stop the MP3. – anthony_s Mar 23 '21 at 21:12
  • How do I accept your help as the answer? I don't see an option. lol – anthony_s Mar 23 '21 at 21:14

1 Answers1

1

You could try Audio session 0 instead of the AudioSessionId

  PresetReverb presetReverb = new PresetReverb(1, 0);
            presetReverb.Preset = PresetReverb.PresetLargehall;
            presetReverb.SetEnabled(true);
            _mediaPlayer.AttachAuxEffect(presetReverb.Id);
            _mediaPlayer.SetAuxEffectSendLevel(1.0f);
Wendy Zang - MSFT
  • 10,509
  • 1
  • 7
  • 17