Hey,
I'm trying to read the length of WAV and AAC/M4A-Files, but it always throws an Exception "Unsupported File".
I tried it with different codes, but it always throws the same Exception.
1st try:
```
public System.TimeSpan getTotalTime(string path)
{
waveOutDevice = new WaveOut();
System.TimeSpan time = new TimeSpan();
if (path.EndsWith(".mp3") == true)
{
time = new Mp3FileReader(path).TotalTime;
}
if (path.EndsWith(".aac") == true | path.EndsWith(".m4a") == true)
{
time = new MediaFoundationReader(path).TotalTime;
}
if (path.EndsWith(".wav") == true)
{
time = new WaveFileReader(path).TotalTime;
}
return time;
}
```
2nd try
```
public System.TimeSpan getTotalTime(string path)
{
waveOutDevice = new WaveOut();
System.TimeSpan time = new TimeSpan();
if (path.EndsWith(".mp3") == true)
{
mainOutputStream = new WaveChannel32(new Mp3FileReader(path));
}
if (path.EndsWith(".aac") == true | path.EndsWith(".m4a") == true)
{
mainOutputStream = new WaveChannel32(new MediaFoundationReader(path));
}
if (path.EndsWith(".wav") == true)
{
mainOutputStream = new WaveChannel32(new WaveFileReader(path));
}
return mainOutputStream.TotalTime;
}
```
None of my trys worked. I also tried different versions.
It should be able to check the Total Length before playing the files, but even if the files are played, i get the same Exception "unsupported file".
But MP3 is working. Only WaveFileReader and MediaFoundationReader are throwing this Exception.
Hope you can help me :)
Comments: well MediaFoundationReader can only handle AAC files if you have an AAC media foundation encoder installed. What OS are you using? You can use the NAudio WPF demo if you want to explore what codecs are installed
I'm trying to read the length of WAV and AAC/M4A-Files, but it always throws an Exception "Unsupported File".
I tried it with different codes, but it always throws the same Exception.
1st try:
```
public System.TimeSpan getTotalTime(string path)
{
waveOutDevice = new WaveOut();
System.TimeSpan time = new TimeSpan();
if (path.EndsWith(".mp3") == true)
{
time = new Mp3FileReader(path).TotalTime;
}
if (path.EndsWith(".aac") == true | path.EndsWith(".m4a") == true)
{
time = new MediaFoundationReader(path).TotalTime;
}
if (path.EndsWith(".wav") == true)
{
time = new WaveFileReader(path).TotalTime;
}
return time;
}
```
2nd try
```
public System.TimeSpan getTotalTime(string path)
{
waveOutDevice = new WaveOut();
System.TimeSpan time = new TimeSpan();
if (path.EndsWith(".mp3") == true)
{
mainOutputStream = new WaveChannel32(new Mp3FileReader(path));
}
if (path.EndsWith(".aac") == true | path.EndsWith(".m4a") == true)
{
mainOutputStream = new WaveChannel32(new MediaFoundationReader(path));
}
if (path.EndsWith(".wav") == true)
{
mainOutputStream = new WaveChannel32(new WaveFileReader(path));
}
return mainOutputStream.TotalTime;
}
```
None of my trys worked. I also tried different versions.
It should be able to check the Total Length before playing the files, but even if the files are played, i get the same Exception "unsupported file".
But MP3 is working. Only WaveFileReader and MediaFoundationReader are throwing this Exception.
Hope you can help me :)
Comments: well MediaFoundationReader can only handle AAC files if you have an AAC media foundation encoder installed. What OS are you using? You can use the NAudio WPF demo if you want to explore what codecs are installed