0

I am using NAudio to convert my mp3 file to waveform image, for this i am using file uploader

<input type="file" name="file" /> 

so user can select their mp3 file and can upload the wave image in particular location in server. If i hard code "c:\media\cat\001\music.mp3" it is working properly, how do i can change according the user uploads.

//here filePath should be "c:\media\cat\001\music.mp3"
using(Mp3FileReader reader = new Mp3FileReader(filePath)) {
      using(WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader)) {

        WaveFileWriter.CreateWaveFile(outputFile, pcmStream);
      }
    }

Please give me some solution for this to get the full path of the file? i know through file upload we never get client file full path, so how to read that file, above code will fit to WPF , how to do in MVC?

manny
  • 1,878
  • 2
  • 15
  • 31

1 Answers1

1

I found the solution to read from url, that way i can pass multiple files to read/stream, here is the code

string filePath = "your mp3 url";

using(Stream ms = new MemoryStream()) {
    using(Stream stream = WebRequest.Create(filePath)
        .GetResponse().GetResponseStream()) {
      byte[] buffer = new byte[32768];
      int read;
      while((read = stream.Read(buffer, 0, buffer.Length)) > 0) {
        ms.Write(buffer, 0, read);
      }
    }

this code will stream mp3 file from url and read the mp3 and keep in memory.

manny
  • 1,878
  • 2
  • 15
  • 31