- Home /
Question by
Cdawg_1999 · Sep 10, 2017 at 02:56 AM ·
audiowwwaudioclip
Unable to import songs using NAudio
I am developing a VR Rhythm Game and am having major difficulty importing audio files from the filesystem. I am using NAudio for all my Audio calls. Here is the script which should handle it, it is run off a button press:
public class songImport : MonoBehaviour {
public void openFile()
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Audio File (*.wav;*.mp3)|*.wav;*.mp3;";
if (open.ShowDialog() != DialogResult.OK) return;
WWW www = null;
if (Path.GetExtension(open.FileName).ToLower() == ".mp3")
{
var rawFileName = Path.GetFileNameWithoutExtension(Path.GetFileName(open.FileName));
var newFileName = Path.Combine(UnityEngine.Application.streamingAssetsPath, rawFileName + ".wav");
using (NAudio.Wave.Mp3FileReader mp3fr = new NAudio.Wave.Mp3FileReader(open.FileName))
{
using (var stream = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(mp3fr))
{
try
{
NAudio.Wave.WaveFileWriter.CreateWaveFile(newFileName, stream);
}
catch(System.Exception e)
{
Debug.Log(e);
}
}
}
www = new WWW("file://"+newFileName);
}
AudioClip clip = www.GetAudioClip();
Music importedSong = new Music(clip, 10, "Jazz", Path.GetFileNameWithoutExtension(open.FileName), "Cameron Hadfield");
MusicController.mc.addToList(importedSong);
createMusicButtons.cmb.populateList();
}
}
Music is a custom class which takes in (AudioClip,BPM,Genre,Filename,Artist) I am unable to get any kind of audioclip it would appear because my call of samples on the clip returns null. Any help is very much so appreciated. Thank you in advance.
Comment
Answer by Cdawg_1999 · Sep 14, 2017 at 03:18 PM
Polite Bump
Please I am looking for any kind of solution to this problem, I have been at this for almost a week now. I am unable to figure out why I cant get the clip information. Is there more I need with www.GetAudioClip()?