Play Audio File (Wav)


Are you searching article and code snippet for Play Audio File

.NET 2.0 provides System.Media Name space to play audio file.

The following code sample shows how to play an audio file using VB.NET


// To play a File from a disk locaiton
Dim objPlayer As New SoundPlayer
objPlayer.SoundLocation = "C:\Alert.wav"
objPlayer.Play()

// To play a File from applcation as embedded resouce
Dim objPlayer As New SoundPlayer
objPlayer.Stream = GetEmbeddedResourceStream()
objPlayer.Play()

Protected Function GetEmbeddedResourceStream() As Stream
Dim objAssembly As System.Reflection.Assembly
Dim soundstream As Stream
objAssembly = System.Reflection.Assembly.LoadFrom(Application.ExecutablePath)
soundstream = objAssembly.GetManifestResourceStream("Alert.wav")
return soundstream
End Function


Comments

Author: Bunty30 Jun 2008 Member Level: Gold   Points : 2

Hi,

Nice piece of code on sound player.

I want to play mp3 format will this player plays that if not give me some suggestion how to create mp3 player.

Thanks for sharing your knowledge.

Keep posting.

Thanks and Regards
S.S.Bajoria

Author: meenu09 Feb 2009 Member Level: Silver   Points : 0

is this code compatible with .net compact framework?



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: