We help IT Professionals succeed at work.

How to merge to music file into a one separate file in VB.NET ?

sa pir
sa pir asked
on
80 Views
Last Modified: 2017-04-16
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)
Comment
Watch Question

DarrenProject Manager / Technical Lead
CERTIFIED EXPERT

Commented:
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.
Project Manager / Technical Lead
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
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:

http://mpgedit.org/mpgedit/mpeg_format/MP3Format.html
DarrenProject Manager / Technical Lead
CERTIFIED EXPERT

Commented:
Closing as question was answered