davidh Posted August 12, 2003 Posted August 12, 2003 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! Quote
Diablicolic Posted August 12, 2003 Posted August 12, 2003 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: Quote "Reality is fake, Dreams are for real"
Leaders dynamic_sysop Posted August 12, 2003 Leaders Posted August 12, 2003 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 Quote
*Gurus* divil Posted August 13, 2003 *Gurus* Posted August 13, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
CJay Posted December 15, 2008 Posted December 15, 2008 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 Quote
MrPaul Posted December 15, 2008 Posted December 15, 2008 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: Quote Never trouble another for what you can do for yourself.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.