Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play an audio file in Windows 7 Phone

I am working on Windows 7 based application development in Silverlight. I have not been able to find a way to play a an audio file in windows 7 phone programmatically. I have been googling it since past few days but i could not get any solution of that. There is a class SoundPlayer in C# but i guess its not available in Windows 7 Phone. Can anyone please help?

like image 934
Aqueel Avatar asked Oct 26 '10 06:10

Aqueel


People also ask

How do I play a .song file?

Open File Manager and navigate to the folder where the audio file is located. Drag the audio file icon from File Manager and drop it on the Audio main window. The Selected file is opened. If Automatically play audio file on Open is selected in the Options-Play dialog box, the audio file starts playing.

How do I play MP3 files on Windows Media Player?

The basic playback of MP3 files and other digital audio files from your Windows Media Player Library is simple. Just navigate through Windows Media Player and double-click or double-tap on a song. Alternatively, you can also select a tune and press Play on the Playback Controls.


2 Answers

You can place a MediaElement in your XAML view:

<MediaElement 
    x:Name="sound" 
    Source="sound.wma" 
    AutoPlay="False" />

then in the code-behind:

sound.Play();

Supported formats are MP3 and WMA.

like image 62
Olivier Payen Avatar answered Oct 10 '22 14:10

Olivier Payen


Use Xna to play the sound. You can cross reference Xna from a Silverlight app though, for playing a sound file, you need to the following:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio
// ...
Stream stream = TitleContainer.OpenStream("sounds/bonk.wav");
SoundEffect effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();

All the best for your application development!

like image 14
prathiraj Avatar answered Oct 10 '22 14:10

prathiraj