title: How to join mp3 and wav files using naudio to byte buffer c# MVC?
body: <p>I found a lot of articles about how to join mp3 or wav files,but i didn't find nothing about how to join audio files of different types.I want to play wav file then mp3 file,one after another.
  I tried to convert wav file to mp3 by using.</p>
  
  <pre><code>  private static MemoryStream ConvertWavToMp3(string path)
      {
  
              if (File.Exists(path))
              {
                  MemoryStream stream = new MemoryStream();
                  using (WaveFileReader rdr = new WaveFileReader(path))
                  using (LameMP3FileWriter wtr = new LameMP3FileWriter(stream, rdr.WaveFormat, 320))
                  {
                      rdr.CopyTo(wtr);
                      return stream;
                  }
              }
              else
              {
                  return null;
              }
          }
      }
  </code></pre>
  
  <p>I get bytes from mp3 file by following code.</p>
  
  <pre><code> private static MemoryStream GetBytesFromMp3(string path)
      {
          string storageName = path.Substring(path.IndexOf("\\\\") + 2, path.IndexOf("\\", 3) - path.IndexOf("\\\\") - 2);
          string networkShare = path.Substring(0, path.LastIndexOf("\\"));
          NetworkCredential credentials = new NetworkCredential(ConfigurationManager.AppSettings[storageName + "_User"], ConfigurationManager.AppSettings[storageName + "_Pass"]);
  
          using (new NetworkConnection(networkShare, credentials))
          {
              if (File.Exists(path))
              {
                  using (Mp3FileReader rdr = new Mp3FileReader(path,FileMode.OpenOrCreate))
                  {
                      byte[] result = new byte[rdr.Length];
                      rdr.Read(result, 0, result.Length);
                      int a = result.Max();
                      MemoryStream stream = new MemoryStream(result);
                      return stream;
                  }
  
              }
              else
              {
                  return null;
              }
          }
      }
  </code></pre>
  
  <p>and and then merge them 
  by </p>
  
  <pre><code>  public static byte[] JoinFiles(List&lt;FileWeb&gt; files)
      {
          MemoryStream output = new MemoryStream();
          int offset = 0;
          foreach (FileWeb file in files)
          {
              MemoryStream mp3Data;
              string fullPath = file.FilePath + "\\" + file.FileName;
  
  
              if (file.FileName.EndsWith("wav"))
              {
                  mp3Data = ConvertWavToMp3(fullPath);
  
              }
              else
              {
                  mp3Data = GetBytesFromMp3(fullPath);
  
              }
  
  
              if (mp3Data != null)
              {
                  byte[] buffer = mp3Data.ToArray();
                  output.Write(buffer, offset, buffer.Length - offset);
                  offset = 4;
              }
          }
          return output.ToArray();
      }
  </code></pre>
  
  <p>But it didn't work.It plays only first part.If i use this code.</p>
  
  <pre><code>public static void Combine(string[] inputFiles, Stream output)
  {
      foreach (string file in inputFiles)
      {
          Mp3FileReader reader = new Mp3FileReader(stream);
          if ((output.Position == 0) &amp;&amp; (reader.Id3v2Tag != null))
          {
              output.Write(reader.Id3v2Tag.RawData, 0, reader.Id3v2Tag.RawData.Length);
          }
          Mp3Frame frame;
          while ((frame = reader.ReadNextFrame()) != null)
          {
              output.Write(frame.RawData, 0, frame.RawData.Length);
          }
      }
  }
  </code></pre>
  
  <p>at <code>Mp3FileReader reader = new Mp3FileReader(stream)</code> i get error no mp3 header found.</p>