Click here to Skip to main content
15,912,578 members
Home / Discussions / C#
   

C#

 
QuestionRecording with Sound Recorder Pin
freshonlineMax27-Jan-06 23:28
freshonlineMax27-Jan-06 23:28 
AnswerRe: Recording with Sound Recorder Pin
S. Senthil Kumar28-Jan-06 9:10
S. Senthil Kumar28-Jan-06 9:10 
AnswerRe: Recording with Sound Recorder Pin
freshonlineMax28-Jan-06 23:16
freshonlineMax28-Jan-06 23:16 
GeneralRe: Recording with Sound Recorder Pin
Saravanan_article29-Jan-06 21:30
Saravanan_article29-Jan-06 21:30 
GeneralRe: Recording with Sound Recorder Pin
freshonlineMax1-Feb-06 18:52
freshonlineMax1-Feb-06 18:52 
Questiondisc-on-key connect checker Pin
Green Fuze27-Jan-06 22:41
Green Fuze27-Jan-06 22:41 
QuestionNumericUpDown controled without arrows from screen Pin
somebody_tr27-Jan-06 19:07
somebody_tr27-Jan-06 19:07 
QuestionPlay WAV file from embedded resources. Pin
ranzask27-Jan-06 15:34
ranzask27-Jan-06 15:34 
Hi all,

I "add" a wav file to my project "file.wav" and made it embedded resource.
now i have seen here and micosoft code to read and play it but
its not working..what am i doing wrong?

my code:

private byte[] m_soundBytes;<br />
        <br />
        private enum Flags<br />
        {           <br />
            SND_ASYNC = 0x0001, <br />
            SND_MEMORY = 0x0004,  <br />
        }<br />
        [DllImport("winmm.dll",CallingConvention = CallingConvention.Winapi)]<br />
        static extern int PlaySound(byte[] wfname,int hMod,int sf);<br />


then there is the class WSounds:

<br />
public WSounds(string s)<br />
{<br />
  string sss = Assembly.GetExecutingAssembly().GetName().ToString();<br />
  Stream a = Assembly.GetExecutingAssembly().GetManifestResourceStream(sss + "." + s);<br />
  m_soundBytes = new byte[a.Length];<br />
  a.Read(m_soundBytes, 0, (int)a.Length);<br />
}<br />
<br />
<br />
public void Play()<br />
{<br />
  PlaySound(m_soundBytes, 0, (int)(Flags.SND_ASYNC | Flags.SND_MEMORY));<br />
}<br />


this line throws exception : m_soundBytes = new byte[a.Length];
so i guess something with the resource is wrong..
i tried another code too:

<br />
System.IO.Stream strTheme = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("file.wav");<br />
        byte[] bytTheme = new byte[strTheme.Length];<br />
        strTheme.Read(bytTheme, 0, (int) strTheme.Length);<br />
<br />


by the way: how do i need to add a WAV file ? under resources sub-dir or on the main project?

Thanks in advance,
Ran

R.Z
AnswerRe: Play WAV file from embedded resources. Pin
[Marc]27-Jan-06 16:30
[Marc]27-Jan-06 16:30 
GeneralRe: Play WAV file from embedded resources. Pin
ranzask27-Jan-06 23:49
ranzask27-Jan-06 23:49 
GeneralRe: Play WAV file from embedded resources. Pin
Curtis Schlak.28-Jan-06 7:40
Curtis Schlak.28-Jan-06 7:40 
AnswerRe: Play WAV file from embedded resources. Pin
Sean Michael Murphy27-Jan-06 17:25
Sean Michael Murphy27-Jan-06 17:25 
GeneralRe: Play WAV file from embedded resources. Pin
ranzask27-Jan-06 23:48
ranzask27-Jan-06 23:48 
GeneralRe: Play WAV file from embedded resources. Pin
Saravanan_article29-Jan-06 22:02
Saravanan_article29-Jan-06 22:02 
GeneralRe: Play WAV file from embedded resources. Pin
ranzask30-Jan-06 0:05
ranzask30-Jan-06 0:05 
QuestionEncode MPEG2 Pin
Emiliano27-Jan-06 14:54
Emiliano27-Jan-06 14:54 
QuestionSliding window and always on top. Pin
RobS27-Jan-06 12:52
RobS27-Jan-06 12:52 
Questionweb services creation Pin
gregoire.b27-Jan-06 12:10
gregoire.b27-Jan-06 12:10 
GeneralRe: web services creation Pin
mast1727-Jan-06 17:53
mast1727-Jan-06 17:53 
QuestionSingle.Parse() Pin
atanamir27-Jan-06 12:05
atanamir27-Jan-06 12:05 
AnswerRe: Single.Parse() Pin
Colin Angus Mackay27-Jan-06 13:50
Colin Angus Mackay27-Jan-06 13:50 
GeneralRe: Single.Parse() Pin
atanamir27-Jan-06 15:11
atanamir27-Jan-06 15:11 
Questionapp.config file Pin
gregoire.b27-Jan-06 9:14
gregoire.b27-Jan-06 9:14 
AnswerRe: app.config file Pin
Michael P Butler27-Jan-06 10:05
Michael P Butler27-Jan-06 10:05 
Questiontype or namespace error in C#(Asp.net) Pin
idreesbadshah27-Jan-06 8:02
idreesbadshah27-Jan-06 8:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.