3

I want to play a mid sound which embedded in my resources file , its in byte , I searched a lot I found most answers like this ,I changed it to my resouces like this

 Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFormsApplication1.Properties.Resources.music.mid");

but it gives me an exception of null

, waht I excactly want is to read this sound , if in byte or another alternative way possible .

Kurubaran
  • 8,696
  • 5
  • 43
  • 65
Dana Ali
  • 261
  • 1
  • 2
  • 5

1 Answers1

0

If you simply set file's build action as Embedded Resource you can access it using:

Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFormsApplication1.music.mid")

If it doesn't work use this code to find the exact name:

For Each strResource As String In Assembly.GetExecutingAssembly().GetManifestResourceNames()
    MsgBox(strResource)
Next strResource
tezzo
  • 10,858
  • 1
  • 25
  • 48
  • The first code says `Obejct is no set to an instans of the object` when i print the resource out ans the second one is not working – Dana Ali Sep 24 '13 at 12:05
  • The second snippet of code is written in VB.NET but you can easily translate it to C#. – tezzo Sep 24 '13 at 12:27
  • This works , but it gives me some names till resources , does not give me resources content – Dana Ali Sep 26 '13 at 06:57
  • The second snippet of code gave you the exact name of the resource. You have to use this name in the first snippet of code. – tezzo Sep 26 '13 at 07:05
  • Thank you , its working now , It gave me a stream , now how to get the url from that stream? – Dana Ali Sep 26 '13 at 07:30
  • Follow every steps in the link you posted. You simply have to create a file and pass his path to WMP. Maybe the biggest problem here is embedding a WindowsMediaPlayer object in your solution but this is another question (http://msdn.microsoft.com/en-us/library/windows/desktop/dd562852%28v=vs.85%29.aspx). Without using WMP you can also try to create a file with your Stream and then call Process.Start() to open it with your default program for .mid file. – tezzo Sep 26 '13 at 07:57