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)
sa pirAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DarrenSenior Software EngineerCommented:
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.
0
DarrenSenior Software EngineerCommented:
I ended up creating my sounds as mp3's with IDv1 data. So in order to play my sounds correctly and in the order I specified I cut off the last 128 bits as these are the ID tags and concatenated the binary of multiple file together and created a temoorary file and played this.

    Private Function PlayVoice(ByVal TicketLetter As String, ByVal TicketNumber As String, ByVal Counter As String) As Boolean

      Dim Result As Integer
      Dim Seek As Long

      Dim Play() As Byte

      Dim Doorbell() As Byte
      Dim Ticket() As Byte
      Dim Number1() As Byte
      Dim Number2() As Byte
      Dim Number3() As Byte
      Dim CounterNumber() As Byte

      Dim Blank() As Byte

      ' Open the Ticket mp3 file.
      Dim MyBinaryReader = New BinaryReader(File.OpenRead("C:\Downloads\Sounds\Melanie Sounds\Splice\T" & TicketLetter & ".mp3"))
      ReDim Ticket(MyBinaryReader.BaseStream.Length - (1 + 128))
      Result = MyBinaryReader.Read(Ticket, 0, MyBinaryReader.BaseStream.Length - 128)

      ' Open the 1st Number mp3 file.
      MyBinaryReader = New BinaryReader(File.OpenRead("C:\Downloads\Sounds\Melanie Sounds\Splice\Number\" & TicketNumber.Substring(0, 1) & ".mp3"))
      ReDim Number1(MyBinaryReader.BaseStream.Length - (1 + 128))
      Result = MyBinaryReader.Read(Number1, 0, MyBinaryReader.BaseStream.Length - 128)

      ' Open the 2nd Number mp3 file.
      MyBinaryReader = New BinaryReader(File.OpenRead("C:\Downloads\Sounds\Melanie Sounds\Splice\Number\" & TicketNumber.Substring(1, 1) & ".mp3"))
      ReDim Number2(MyBinaryReader.BaseStream.Length - (1 + 128))
      Result = MyBinaryReader.Read(Number2, 0, MyBinaryReader.BaseStream.Length - 128)

      ' Open the 3rd Number mp3 file.
      MyBinaryReader = New BinaryReader(File.OpenRead("C:\Downloads\Sounds\Melanie Sounds\Splice\Number\" & TicketNumber.Substring(2, 1) & ".mp3"))
      ReDim Number3(MyBinaryReader.BaseStream.Length - (1 + 128))
      Result = MyBinaryReader.Read(Number3, 0, MyBinaryReader.BaseStream.Length - 128)

      ' Open the Counter Number mp3 file.
      MyBinaryReader = New BinaryReader(File.OpenRead("C:\Downloads\Sounds\Melanie Sounds\Splice\Counter\C" & Counter & ".mp3"))
      ReDim CounterNumber(MyBinaryReader.BaseStream.Length - 1)
      Result = MyBinaryReader.Read(CounterNumber, 0, MyBinaryReader.BaseStream.Length - 1)

      ReDim Play(Ticket.Length + Number1.Length + Number2.Length + Number3.Length + CounterNumber.Length)

      Ticket.CopyTo(Play, 0)
      Number1.CopyTo(Play, Ticket.Length)
      Number2.CopyTo(Play, Ticket.Length + Number1.Length)
      Number3.CopyTo(Play, Ticket.Length + Number1.Length + Number2.Length)
      CounterNumber.CopyTo(Play, Ticket.Length + Number1.Length + Number2.Length + Number3.Length)

      Dim TmpFileName As String = Path.GetTempFileName()
      Dim TmpFileNameNoExtension As String = Path.GetFileNameWithoutExtension(TmpFileName)

      Dim MyBinaryWriter As BinaryWriter = New BinaryWriter(File.OpenWrite("C:\Downloads\" & TmpFileNameNoExtension & ".mp3"))

      MyBinaryWriter.Write(Play)

      MyBinaryReader.Close()
      MyBinaryWriter.Close()

      MyPlayer.playlistClear()
      MyPlayer.addTarget("C:\Downloads\" & TmpFileNameNoExtension & ".mp3", Nothing, AXVLC.VLCPlaylistMode.VLCPlayListReplaceAndGo, 0)

      'File.Delete("C:\Downloads\" & TmpFileNameNoExtension & ".mp3")

    End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽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
0
DarrenSenior Software EngineerCommented:
Closing as question was answered
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
music

From novice to tech pro — start learning today.