jfversluis / Plugin.Maui.Audio

Plugin.Maui.Audio provides the ability to play audio inside a .NET MAUI application
MIT License
245 stars 39 forks source link

Playback latency #89

Open githubjanson opened 6 months ago

githubjanson commented 6 months ago

In my mobile app, I need a short sound to play when I tap a button. And I need as good precision as possible, that is, as short latency between the tap and the sound as possible.

But the latency is approximately 150-200 ms when running the app on a (modern) iPhone, which is not good enough for my application. There are similar apps out there (non-MAUI), where this lag is significantly less, so it is not hardware related.

I assume that this lag is not related to the Maui.Audio plugin, but perhaps someone has a clue or workaround how to get around this issue? Do I need to switch to another platform?

Thanks.

bijington commented 6 months ago

It is interesting that you are seeing some latency. Out of interest how are you measuring this latency?

A couple of things that I would try:

  1. Check that your sound starts right at the beginning of the file and there isn't any silence mimicking latency.
  2. If you are using a Command/Clicked event swap to using the Pressed event on the Button to see if you can get a quicker response.
githubjanson commented 6 months ago

@bijington, thanks for your tips! Changing to the Pressed event didn't help but made me realize that the latency is in the Button control and not related to the sound playback at all. When I press the button (and hold) there is a delay before the button "reacts". For the default MAUI button this is shown by the text turning grey. And at that exact moment, my sound plays.

So what I need is a button with shorter response time.

Regarding the latency, I have not measured it but rather estimated it by comparison. I am developing a rythmic exercise app, and I guess a latency around 50 ms would be acceptable, 25 ms would be great.

borrmann commented 2 months ago

@githubjanson out of curiosity did you find a solution for this issue? If not, are you using compiled bindings or have you filed an issue in the MAUI repo?

its-jefe commented 1 month ago

Seems unlikely a problem with Plugin.Maui.Audio. Other MAUI elements don't seem to have a latency but I noticed a delay on button clicks as well. I have tried calling play from event triggers of pressed and clicked. Then from inside a custom button OnPressed.

I am also curious to know @githubjanson if you found a solution.

githubjanson commented 1 month ago

Hi @borrmann, @its-jefe,

I skipped the Button control and am using the SKCanvasView/Touch event instead. This gives me the best experience, i.e., a minimal latency beteen the tap and the sound.