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)
* musicVisual Basic.NET

Avatar of undefined
Last Comment
Darren

8/22/2022 - Mon
Darren

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.
ASKER CERTIFIED SOLUTION
Darren

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
kaufmed

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
Darren

Closing as question was answered
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck