Kian
Kian

Reputation: 11

Can't import WAV files into Visual Studio

I upgraded to Visual Studio 2015 from 2012, and it royally screwed me over. I can no longer import WAV files into my project's resources without it turning them into a MemoryStream, which my code won't accept. I have been searching for hours now, and I am getting really frustrated. Will someone please help me with this? I am importing the files exactly according to these instrutions: How to: Import or Export Resources

Let me know if you need pictures or other info. I am getting really desperate at this point.

Upvotes: 1

Views: 1176

Answers (2)

jmcilhinney
jmcilhinney

Reputation: 54417

I don't know exactly what experience you think you had in VS 2012 but I just tested VS 2015, 2013 and 2012 and they all worked exactly the same way. I simply opened the project properties, selected the Resources page, clicked the Add Resource drop-down, selected Add Existing File and navigated to the WAV file I wanted. The file was added as a resource and the corresponding property of My.Settings exposed that resource as type UnmanagedMemoryStream. As I said, that happened exactly the same way in all three versions. If you got something different in VS 2012 then you did something different in VS 2012. You haven't told us what you did so we can only guess.

Exactly what type of data does your code expect? Maybe that would have been good information to provide too. If it's a Byte array then you can get one from that resource Stream like so:

Dim resourceStream = My.Resources.MyWavResource
Dim length = CInt(resourceStream.Length)
Dim resourceData(length - 1) As Byte

resourceStream.Read(resourceData, 0, length)

That's exactly how you read from any Stream to a Byte array. You could, if you needed to do this more than once, put that into a method:

Private Function GetStreamData(stream As Stream) As Byte()
    Dim length = CInt(stream.Length)
    Dim data(length - 1) As Byte

    stream.Read(data, 0, length)

    Return data
End Function

You could call it like this:

Dim data As Byte()

Using resource = My.Resources.MyWavResource
    data = GetStreamData(resource)
End Using

You could even write it as an extension method and then call it on the Stream itself.

Upvotes: 1

user6638270
user6638270

Reputation:

The link you are using is VS 2010.

Open your Resource file. By default the Top Left menu is Strings; but there is a small drop down arrow. Click this and the fourth option is Audio. If you now click add existing file, by default it will filter for .wav files, and will add them as such.

Upvotes: 0

Related Questions