Play two sounds simultaneously in a Windows 8 Metro app (C # / XAML)

I have a Windows 8 Metro app (C # / XAML): How can I play the same sound effect twice so that it plays simultaneously.

The second playback should begin before the first ends.

Related questions:

Play two sounds at the same time C # and Play two sounds at the same time

I found this class for XNA that does what I want but is not available in Metro: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.audio.soundeffectinstance.aspx

+6
source share
1 answer

Just create a separate media element for each sound effect.

(not sure if I need to move the file every time)

public async void PlayLaserSound() { var package = Windows.ApplicationModel.Package.Current; var installedLocation = package.InstalledLocation; var storageFile = await installedLocation.GetFileAsync("Assets\\Sounds\\lazer.mp3"); if (storageFile != null) { var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read); MediaElement snd = new MediaElement(); snd.SetSource(stream, storageFile.ContentType); snd.Play(); } } 
+17
source

Source: https://habr.com/ru/post/917683/


All Articles