Resource files containing WAV files 
Author Message
 Resource files containing WAV files

I found an example of what I want to do for VB6, but cannot figure out how
to do it in .NET .

I would like to load a small wave file as a resource file so that I can
avoid disk access each time it is used.  I would like it complied into the
program binary so that it is always available fast.

Can this be done in .NET ?

Any hints or reading suggestions would be appreciated.

Thanks,

Ross



Mon, 27 Jun 2005 05:07:58 GMT  
 Resource files containing WAV files
Add a wav file to you app and set Build Action to Embedded Resource then use
this code:

Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByRef
adr As Byte, ByVal hModule As Int32, ByVal dwFlags As Int32) As Int32
 Dim str As Stream =
System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("Y
ourAppName.filename.wav")
 Dim len As Int32 = CInt(str.Length - 1)
 Dim bytes(len) As Byte
 str.Read(bytes, 0, len)
 PlaySound(bytes(0), 0, 4)

HTH

--
Corrado Cavalli [Microsoft MVP]
UGIdotNET - http://www.ugidotnet.org



Mon, 27 Jun 2005 07:15:29 GMT  
 Resource files containing WAV files
Thanks for the help.

It took me a while to figure out how to add a wav file to the project, but I
got it done.  After trying so many ways, not sure I can remember how, but it
is there, and I got the Build action figured out as well.   I had the Import
statements in a Module1, but figured out that I have to have them in the
individual form where this code resides, not quite sure I understand that...

I had a problem with the :  ---  Dim bytes(len) As Byte   ---  statement.

Error message on Compile "Constant expression required" .

Just to try to get it to work, I looked up the size of the wav file,
subtracted 1 and used that number as a constant.  It compiled fine, but
still does not play when it is called.

Any thoughts?  Perhaps I will sleep on it and see if it looks easier
tommorrow.  Suspect I am one small step away.

Thanks a lot for your assistance.  It has been years since I have coded
anything, much has changed...

Ross



Quote:
> Add a wav file to you app and set Build Action to Embedded Resource then
use
> this code:

> Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA"
(ByRef
> adr As Byte, ByVal hModule As Int32, ByVal dwFlags As Int32) As Int32
>  Dim str As Stream =

System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("Y
Quote:
> ourAppName.filename.wav")
>  Dim len As Int32 = CInt(str.Length - 1)
>  Dim bytes(len) As Byte
>  str.Read(bytes, 0, len)
>  PlaySound(bytes(0), 0, 4)

> HTH

> --
> Corrado Cavalli [Microsoft MVP]
> UGIdotNET - http://www.ugidotnet.org



Mon, 27 Jun 2005 11:17:20 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Accessing a WAV file contained in a Resource file (VB4)

2. Problem Loading .wav file from Resource File...

3. WAV files and resource files

4. opening resource file-based WAV files

5. Newbie (kind of)- Wav files in a Resource File

6. Embeding a wav file into a resource file

7. How to save bitmaps/wav files in Resource File

8. Wav files from Resource file

9. Wav files from Resource file

10. opening resource file-based WAV files

11. inserting wav files into other wav files

12. Create a new .wav file from an existing .wav file based on the date

 

 
Powered by phpBB® Forum Software