Reputation: 309
In My case I want to play a sound file from a C# class file. I refer the examples with create Media Element in the xaml page. I want to play a sound every 5 minutes. This process is behind of my application. I don't have a design page for this.
Upvotes: 1
Views: 1502
Reputation: 13994
If your sound is a WAV file, try this:
Stream stream = TitleContainer.OpenStream("sounds/bonk.wav");
SoundEffect effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
Update
Please, take into account that SoundEffect class lives in Microsoft.Xna.Framework.Audio namespace and is part of the XNA Framework Class Library, which is not supported on Windows Phone 8.1 Runtime apps (not Silverlight one). This means that if you are planning to upgrade/port your application to universal either for Windows Phone 8.1 (and upper) or Windows 8.1 (and upper), this answer will not work for you, unfortunately.
Upvotes: 2
Reputation: 1864
Simply declare your Media Element in code:
MediaElement element = new MediaElement();
Upvotes: 0