Link to home
Start Free TrialLog in
Avatar of sa pir
sa pir

asked on

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. !!!
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)
Avatar of Darren
Flag of Ireland image

You will have to cut off the first few bytes on the second MP3 before merging.

I've done this before but I'll have to try to did out the code.
Avatar of Darren
Flag of Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
MP3s have header information as well as the music data. You can't just splice together the bytes of two MP3s because you'll be putting header-music-header-music into the file. In effect, the 2nd song won't exist. You need to parse out the music data from the second file and append it to the first song's music data. You'll also need to update the spliced file's header information to account for the new length.

MP3 is actually a proprietary format. You can find some information at the following link:
Closing as question was answered