Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to merge to music file into a one separate file in vb.net ?


the following code that i have tried merges to music file but only first music plays because of length or something. !!!

What I have tried:

Dim s1 As Byte() = File.ReadAllBytes("e:\Music\Voice 001.mp3")
      Dim s2 As Byte() = File.ReadAllBytes("e:\Music\Voice 002.mp3")
      Dim adWithSong As Byte() = New Byte(s1.Length + s2.Length) {}
      s1.CopyTo(adWithSong, 0)
      s2.CopyTo(adWithSong, s1.Length)
      Dim newFilePath As String = "e:\Music\test1.mp3"
      File.WriteAllBytes(newFilePath, adWithSong)
Posted
Updated 25-Mar-17 20:35pm

You cannot simply concatenate sound or video files.

Sound and video files contain structured data with headers giving details on the data that follows and other information such as tags that give information about the file but are nothing to do with the actual sound data.

See the MP3 file format;

MP3 File Format Specification[^]

MP3 - Wikipedia[^]

Also, put MP3 in the search box on this site to see code examples of manipulating MP3's.
 
Share this answer
 
v2
The main problem is your misconception of MP3 files.
Your can't just append 1 after the other and expect getting 1 big mp3 file that work.
Basically, you need a library that can decode an MP3 file and:
Load/decode the first mp3 file
Load/decode the second mp3 file
merge them using the library
encode/save the big mp3
 
Share this answer
 
Comments
saeid.piran 26-Mar-17 2:54am    
Thanks for Your Reply.
How about Wave or Other Formats?
is it possible to concatenate them?
Patrice T 26-Mar-17 3:47am    
Only flat text can be concatened a,d keep some meaning.
For about all other file formats, it don't work. The second file is garbage ant the end from the point of view of the first.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900