title: Using NAudio to create AudioClip in Unity, freezes 1-2 seconds while reading data
body: <p>I am currently using the below code in my Unity project to stream mp3 files from a directory. It works great however, it freezes while the file is read in and the float is filled.
  As this project is in VR the freezes are very jarring. How can I resolve it so that it can read in without the lockup? Do I try and put it on another thread? </p>
  
  <p>When commenting out the below lines there are no hitches.</p>
  
  <p><strong>aud = new AudioFileReader(musicPath);</strong></p>
  
  <p><strong>aud.Read(AudioData, 0, (int)aud.Length);</strong></p>
  
  <pre><code>    public void LoadSong(string musicPath){
  
      //Set title of song
      songTitle = Path.GetFileNameWithoutExtension(musicPath);
      if(songTitle != currentlyPlaying &amp;&amp; songTitle != lastPlayedTitle){
          //Parse the file with NAudio
          aud = new AudioFileReader(musicPath);
  
          //Create an empty float to fill with song data
          AudioData = new float[aud.Length];
          //Read the file and fill the float
          aud.Read(AudioData, 0, (int)aud.Length);
  
          //Create a clip file the size needed to collect the sound data
          craftClip = AudioClip.Create(songTitle, (int)aud.Length, aud.WaveFormat.Channels, aud.WaveFormat.SampleRate, false);
          //Fill the file with the sound data
          craftClip.SetData(AudioData, 0);
  
          if(craftClip.isReadyToPlay){
              playMusic(craftClip, songTitle);
              aud.Dispose();
           }
  
          }
  
          else
          {
              playMusic(lastPlayedAudioFile, lastPlayedTitle);
          }
  
  }
  </code></pre>
  
  <p>I have also tried to download the file as mentioned in this question <a href="https://answers.unity.com/questions/933090/wwwgetaudioclip-streaming-of-mp3-on-this-plattform.html" rel="nofollow noreferrer">https://answers.unity.com/questions/933090/wwwgetaudioclip-streaming-of-mp3-on-this-plattform.html</a> using the below code and I receive the Streaming of 'mp3' on this platform is not supported error despite including the file type. Here is the code I used.</p>
  
  <pre><code>public class AudioDownloadTest : MonoBehaviour {
  public AudioSource playThis;
  public AudioClip clipy;
  string pathh = @"D:\TestFiles\IntheAirTonightShort.mp3";
  
  IEnumerator Download(string pathh){
      WWW song = new WWW(pathh);
      yield return song;
      clipy = song.GetAudioClip(false,false,AudioType.MPEG);
      playThis.clip = clipy;
  }
  
  void Start () {
      StartCoroutine(Download(pathh));
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have managed to improve the situation slightly by storing the last played song so that if the user selects the previous song that was played there is no delay.</p>
  
  <p>Many thanks</p>