Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

How can I copy an MP3 file that is embedded in my .exe file out to a file?

 

I've managed to copy it to a stream from the resources, but I'm confused as to how to write it to the file now. I've copied it to a stream using the following code,

 

Dim assm As [Assembly] = [Assembly].GetExecutingAssembly

Dim str As Stream

Dim strResourceName As String = "Project.TRK0" & intTrackNumber & ".mp3"

str = assm.GetManifestResourceStream(strResourceName)

 

but I'm now struggling to copy it out to a file now.

 

Thanks for any help!

Posted
I'm having serious problems with that too, I mean I was able to copy the .mp3, but the .mp3 that I copied...was 0kb...I mean like nothing :confused:
"Reality is fake, Dreams are for real"
  • Leaders
Posted

after a bit of messing with streams , i embedded an mp3 in to an app and successfully copied it from manifeststream to the hd. here's a quick example of how to.

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

       Try
           Dim sWriter As Stream = (Me.GetType().Assembly.GetManifestResourceStream("count_down.Big Brovaz - Nu Flow.mp3"))
           Dim x As Integer
           Dim fFile As New FileStream("C:\test.mp3", FileMode.OpenOrCreate)
           For x = 1 To sWriter.Length
               fFile.WriteByte(sWriter.ReadByte)
           Next
           fFile.Close()

       Catch ex As Exception
           MessageBox.Show(ex.Message)
       End Try

   End Sub

  • *Gurus*
Posted
A slightly better way (not to mention faster) would be to read larger chunks than one byte at a time. You can get the length of the file in memory via the Length property of the stream. You'll see a big performance increase.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • 5 years later...
Posted

How I that ^ Done then please?

 

and for the other code i got Errors :( y?

 

Errors:

 

Type 'Stream' is Not Defined

 

Error 2:

 

Type 'fFile' is Not Defined

 

Please help

Posted

Imports statement

 

Assuming you're using VB.NET, you need to have the following line at the top of your source file:

 

Imports System.IO

 

The following declarations would also be useful:

 

Option Strict On
Option Explicit On

 

You can find explanations of these statements on MSDN.

 

Good luck :cool:

Never trouble another for what you can do for yourself.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...