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.

Était-ce utile?

La 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 ();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top