Question

I am trying to stop playing a sound when the screen is touched. Currently the sound is being played with

AudioToolbox.SystemSound.FromFile("sound.mp3").PlaySystemSound();

I have a UIEvent in another class that fires on all touches. I want to add the functionality to stop playing the audio to this event, however I'm unable to figure out how to do so.

From searching online, I've seen people being recommended to use AVAudioPlayer instead of AudioToolbox, but I'm not able to find how to stop the audio playing using AudioToolbox either.

Was it helpful?

Solution

Try to destroy instance:

// start playing
var sound = AudioToolbox.SystemSound.FromFile("sound.mp3");
sound.PlaySystemSound();

// Stop playing
sound.Close (); // Alternatively, try to sound.Dispose ();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top