Playing WAV from Embedded Resource 
Author Message
 Playing WAV from Embedded Resource

Hi,

I am trying to play a wav from an embedded resource.  I have added a file
and changed the BuildAction to Embedded Resource.  I can not get the stream
to play.  It says the stream length is nothing.  Can somebody please help.
Below is the code.

Thanks,

Dan

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySound" (ByVal
pszSound() As Byte, ByVal hMod As Int16, ByVal fdwSound As Long) As Boolean

Public RetValue As Boolean

Public Enum zzSound

Async = &H1L

Memory = &H4L

Resource = &H40004L

Sync = &H0L

End Enum

Public Sub PlayAudioFromRes(ByVal filename As String)

Dim oAssembly As Reflection.Assembly = MyClass.GetType.Assembly

Dim Stream As System.IO.Stream

Dim buffer() As Byte

filename = oAssembly.GetName.Name & "." & filename

Stream = oAssembly.GetManifestResourceStream(filename)

ReDim buffer(CType(Stream.Length, Integer))

Stream.Read(buffer, 0, buffer.Length)

RetValue = PlaySound(buffer, 0, zzSound.Memory + zzSound.Async)

End Sub



Thu, 06 Oct 2005 22:49:23 GMT  
 Playing WAV from Embedded Resource
Hi, try changing this:
Quote:
> Dim oAssembly As Reflection.Assembly = MyClass.GetType.Assembly

to this:

Dim oAssembly As Reflection.Assembly =
Reflection.Assembly.GetExecutingAssembly

--
Happy to help,
-- Tom Spink


Quote:
> Hi,

> I am trying to play a wav from an embedded resource.  I have added a file
> and changed the BuildAction to Embedded Resource.  I can not get the
stream
> to play.  It says the stream length is nothing.  Can somebody please help.
> Below is the code.

> Thanks,

> Dan

> Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySound"
(ByVal
> pszSound() As Byte, ByVal hMod As Int16, ByVal fdwSound As Long) As
Boolean

> Public RetValue As Boolean

> Public Enum zzSound

> Async = &H1L

> Memory = &H4L

> Resource = &H40004L

> Sync = &H0L

> End Enum

> Public Sub PlayAudioFromRes(ByVal filename As String)

> Dim oAssembly As Reflection.Assembly = MyClass.GetType.Assembly

> Dim Stream As System.IO.Stream

> Dim buffer() As Byte

> filename = oAssembly.GetName.Name & "." & filename

> Stream = oAssembly.GetManifestResourceStream(filename)

> ReDim buffer(CType(Stream.Length, Integer))

> Stream.Read(buffer, 0, buffer.Length)

> RetValue = PlaySound(buffer, 0, zzSound.Memory + zzSound.Async)

> End Sub



Fri, 07 Oct 2005 00:09:49 GMT  
 Playing WAV from Embedded Resource
Hi Daniel,

I replied the same question in the microsoft.public.dotnet.general group.
Feel free to let me know if there is anything unclear.

Regards,

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

Quote:

>Subject: Playing WAV from Embedded Resource
>Date: Sun, 20 Apr 2003 10:49:23 -0400
>Lines: 50
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.3790.0
>X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.3790.0

>Newsgroups:

microsoft.public.dotnet.framework.windowsforms,microsoft.public.dotnet.gener
al,microsoft.public.dotnet.languages.vb
Quote:
>NNTP-Posting-Host: host-64-179-39-13.har.choiceone.net 64.179.39.13
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:91709

microsoft.public.dotnet.languages.vb:102815
microsoft.public.dotnet.framework.windowsforms:43105
Quote:
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb

>Hi,

>I am trying to play a wav from an embedded resource.  I have added a file
>and changed the BuildAction to Embedded Resource.  I can not get the stream
>to play.  It says the stream length is nothing.  Can somebody please help.
>Below is the code.

>Thanks,

>Dan

>Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySound" (ByVal
>pszSound() As Byte, ByVal hMod As Int16, ByVal fdwSound As Long) As Boolean

>Public RetValue As Boolean

>Public Enum zzSound

>Async = &H1L

>Memory = &H4L

>Resource = &H40004L

>Sync = &H0L

>End Enum

>Public Sub PlayAudioFromRes(ByVal filename As String)

>Dim oAssembly As Reflection.Assembly = MyClass.GetType.Assembly

>Dim Stream As System.IO.Stream

>Dim buffer() As Byte

>filename = oAssembly.GetName.Name & "." & filename

>Stream = oAssembly.GetManifestResourceStream(filename)

>ReDim buffer(CType(Stream.Length, Integer))

>Stream.Read(buffer, 0, buffer.Length)

>RetValue = PlaySound(buffer, 0, zzSound.Memory + zzSound.Async)

>End Sub



Fri, 07 Oct 2005 16:36:56 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to embed and play a WAV file

2. Playing .wav data in a resource (.res) file?

3. Playing WAV stored in a DLL as a resource

4. Playing a .wav stored in a Resource file.

5. Play a .wav included as a resource

6. Playing a WAV File stored as a VB6 resource

7. Extract embedded .wav objects?

8. Embedding .Wav files

9. Embedding .Wav files

10. Embedding a .wav file into VB project?

11. Code to play embedded sound file

12. embedding resources

 

 
Powered by phpBB® Forum Software