2
votes

I'm using Xamarin-Forms-Labs ISoundService in Xamarin to play audio in a Timer.

Every 30 seconds I have it play an audio file (each file is different)

I can get it to play subsequent files if the file size is small (less than 5k) but if it larger is keeps replaying the "larger audio" file in place of the subsequent clips.

Any thoughts how I can resolve this? Am I "stopping" the audio properly. Should I async stop since it is async play?

I appreciate the time and expertise

Xamarin-Forms-Labs ISoundService https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/src/Platform/XLabs.Platform/Services/Media/ISoundService.cs

My code

                var audioFile = intervalSettingsAudioDict[currentInterval];
                Console.WriteLine(audioFile);
                soundService = DependencyService.Get<ISoundService>();

                if (soundService.IsPlaying){
                    soundService.Stop();
                }

                soundService.Volume = 1.0;
                soundService.PlayAsync(audioFile);
1

1 Answers

0
votes

I think the problem is that the default behavior of DependencyService.Get() is to act as a Singleton: http://forums.xamarin.com/discussion/22174/is-a-dependencyservice-implementation-class-treated-as-a-singleton.

I solved it using the following:

var SoundService = DependencyService.Get<ISoundService>(DependencyFetchTarget.NewInstance);

This worked on iOS, but I'm still troubleshooting an unrelated problem on Android.

HTH.