jcphlux / XamarinAudioManager

Cross platform Audio Manager for Xamarin
MIT License
36 stars 6 forks source link

Sound doesn't play the first time on Android #12

Open joelman opened 7 years ago

joelman commented 7 years ago

First of all, thanks for your great work on this. It seems like just what I need. That being said, there's a problem when running the Droid project. The sound doesn't play the first time, only if I click my button again. Has anyone else experienced this?

I created a simple demo here https://github.com/joelman/Audiotest

It also happens on your Demo project. If I put a breakpoint in DroidAudioManager here

var soundId = await _soundPool.LoadAsync(file, priority);

Then it works. So it may be something about the Async task.

I'm using Xamarin Studio (Community) 6.1.5

aquynh commented 7 years ago

confirmed this issue on Android 7. even when i try to work-around this problem by playing 2 times, it still doesnt work. any plans to fix this?

this is a very useful plugin, thanks for your amazing work!

jcphlux commented 7 years ago

I will try to get this working this week. I have been swamped at work.

Flying--Dutchman commented 7 years ago

I also have this issue. Is there a workaround?

Flying--Dutchman commented 7 years ago

Ok, found a (quick and dirty) workaround. I call a async Init method on my MasterPage.xaml.cs with following content: private async void Init() { Audio.Manager.EffectsOn = true; float vol = Audio.Manager.EffectsVolume; Audio.Manager.EffectsVolume = 0; await Audio.Manager.PlaySound("ok.mp3"); await Audio.Manager.PlaySound("alert.mp3"); await Audio.Manager.PlaySound("negative.mp3"); Audio.Manager.EffectsVolume = vol; }

For some reason I have to initialize each audio file that i use in my project.

si618 commented 7 years ago

Just hit this as well. Hooking into App.OnStart event and initialising from there worked for me.