C# PCM data audio player for Silverlight 5
Is th开发者_JAVA技巧ere a way in SilverLight 5 to play PCM data? This could be obtained from a stream from a web Server or obtained by reading a WAV file.
Any help would be greatly appreciated.
Silverlight 5 includes a class from the XNA Framework, namely Microsoft.Xna.Framework.Audio
. This contains a type SoundEffect
which you can use to play PCM data. (Since SL5 includes the class, I don't think you'll need to add any additional references)
var myAudioStream = Application.GetResourceStream(new Uri("PCMSound.wav", UriKind.RelativeOrAbsolute));
SoundEffect effect = SoundEffect.FromStream(myAudioStream);
effect.Play();
There are overloads for the Play
method which you can see here. One thing to note is that there are limitations in terms of the types of wav
files you can use:
Files must be PCM Encoded, 8 or 16 bit mono or stereo and either 22.5khz, 44.1khz or 48khz sample rates.
精彩评论