|
-
Sep 20th, 2008, 07:33 AM
#1
Thread Starter
Member
[RESOLVED] [2005] Extract embedded .wav's?
How can I extract a .wav to the disk from my resources?
-
Sep 20th, 2008, 07:47 AM
#2
Addicted Member
Re: [2005] Extract embedded .wav's?
We assume that its saved as bytes.
Create i FileStream object, call the function .Write(). Then you're actually done.
vb.net Code:
Dim fs As System.IO.FileStream = New System.IO.FileStream("Path/<filename>", IO.FileMode.Create)
fs.Write(My.Resources.<filename>, 0, My.Resources.<filename>.Length)
-
Sep 20th, 2008, 07:54 AM
#3
Thread Starter
Member
Re: [2005] Extract embedded .wav's?
Error 1 Value of type 'System.IO.UnmanagedMemoryStream' cannot be converted to '1-dimensional array of Byte'.
-
Sep 20th, 2008, 09:30 PM
#4
Thread Starter
Member
Re: [2005] Extract embedded .wav's?
what's the alternative to saving a file inside of your application, and possibly compressing those files?
-
Sep 21st, 2008, 02:54 AM
#5
Addicted Member
Re: [2005] Extract embedded .wav's?
Oh its a unmanagedstream... Hm.. sorry i don't know about that one 
Well the alternative in saving a wav file is to delete the .wav exstension before you put it into the resources. Then it will be saved in bytes, and when you extract it you just put the .wav on again.
-
Sep 21st, 2008, 06:13 PM
#6
Re: [2005] Extract embedded .wav's?
try this:
vb Code:
Dim byteArray() As Byte = My.Resources.resourcename
Dim fs As New IO.FileStream(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Temp, "sound.wav"), IO.FileMode.Create)
fs.Write(byteArray, 0, byteArray.Length)
fs.Close()
My.Computer.Audio.Play(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Temp, "sound.wav"))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 22nd, 2008, 02:07 AM
#7
Re: [2005] Extract embedded .wav's?
Why exactly do you want to save it as a file? You can play it without saving it. The SoundPlayer class can be instantiated using a Stream and My.Computer.Audio.Play will accept a Byte array or Stream as well as a file path.
-
Sep 22nd, 2008, 07:01 AM
#8
Thread Starter
Member
Re: [2005] Extract embedded .wav's?
I don't want to play it, just extract it at the necessary time.
-
Sep 22nd, 2008, 07:04 AM
#9
Thread Starter
Member
Re: [2005] Extract embedded .wav's?
 Originally Posted by .paul.
try this:
vb Code:
Dim byteArray() As Byte = My.Resources.resourcename
Dim fs As New IO.FileStream(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Temp, "sound.wav"), IO.FileMode.Create)
fs.Write(byteArray, 0, byteArray.Length)
fs.Close()
My.Computer.Audio.Play(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Temp, "sound.wav"))
Error 1 Value of type 'System.IO.UnmanagedMemoryStream' cannot be converted to '1-dimensional array of Byte'.
-
Sep 22nd, 2008, 09:13 AM
#10
Re: [2005] Extract embedded .wav's?
I was under the impression, as it appears that Link and .paul. were, that WAV files embedded as resources were returned by My.Resources as Byte arrays. Apparently that isn't the case. You now know that they are returned as UnmanagedMemoryStream objects. So, what did you find out when you read the Help documentation for the UnmanagedMemoryStream class?
What's that? You didn't read the Help documentation? You're not alone, more's the pity. It should be the first place people look but it's apparently the last place far too many people think of. The UnmanagedMemoryStream class, like all streams, has a Read method that will read the contents to a Byte array and a Length property to tell you how many Bytes it contains. Once you've got a Byte array you can use a FileStream to write it to disk.
You might choose to use a single big read and a single big write, or you may choose to perform multiple read and write operations until all the data has been transferred.
-
Sep 23rd, 2008, 07:23 AM
#11
Thread Starter
Member
Re: [2005] Extract embedded .wav's?
I tried to read the page on the msdn (http://msdn.microsoft.com/en-us/libr...ream.read.aspx) for it and the only example is in c#, I don't really understand it enough to convert to vb
i tried this and got "Object reference not set to an instance of an object." for test(i) = My.Resources.enraged.ReadByte()
Code:
Dim test() As Byte
Dim i As Integer
For i = 0 To My.Resources.test.Length - 1
test(i) = My.Resources.test.ReadByte()
Next
-
Sep 23rd, 2008, 07:47 AM
#12
Re: [2005] Extract embedded .wav's?
try this:
vb Code:
Dim size As Long = My.Resources.test.Length - 1
Dim buffer(CInt(size)) As Byte
Dim offset As Integer = 0
Dim count As Integer = CInt(size)
Dim returnValue As Integer
returnValue = My.Resources.test.Read(buffer, offset, count)
Dim fs As New IO.FileStream(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Temp, "sound.wav"), IO.FileMode.Create)
fs.Write(buffer, 0, buffer.Length)
fs.Close()
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 23rd, 2008, 10:30 PM
#13
Thread Starter
Member
Re: [2005] Extract embedded .wav's?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|