private static IAudioStream TryOpenSourceStream(FileInfo fileInfo) { WaveStream waveStream; if ((waveStream = OpenFile(fileInfo)) != null) { return(new NAudioSourceStream(waveStream)); } else if (FFmpegSourceStream.WaveProxySuggested(fileInfo)) { Console.WriteLine("File format with known seek problems, creating proxy file..."); return(TryOpenSourceStream(FFmpegSourceStream.CreateWaveProxy(fileInfo))); } else { try { FFmpegSourceStream stream = new FFmpegSourceStream(fileInfo); // Make a seek to test if it works or if it throws an exception stream.Position = 0; return(stream); } catch (FFmpegSourceStream.FileNotSeekableException) { /* * This exception gets thrown if a file is not seekable and therefore cannot * provide all the functionality that is needed for an IAudioStream, although * the problem could be solved by creating a seek index. See FFmpegSourceStream * for further information. * * For now, we create a WAV proxy file, because it is easier (consumes * additional space though). */ Console.WriteLine("File not seekable, creating proxy file..."); return(TryOpenSourceStream(FFmpegSourceStream.CreateWaveProxy(fileInfo))); } catch (FFmpegSourceStream.FileSeekException) { /* * This exception gets thrown if a file should be seekable but seeking still does * not work correctly. We also create a proxy in this case. */ Console.WriteLine("File test seek failed, creating proxy file..."); return(TryOpenSourceStream(FFmpegSourceStream.CreateWaveProxy(fileInfo))); } catch (DllNotFoundException e) { throw new DllNotFoundException("Cannot open file through FFmpeg: DLL missing", e); } } }
private static IAudioStream TryOpenSourceStream(FileInfo fileInfo) { WaveStream waveStream; if ((waveStream = OpenFile(fileInfo)) != null) { return(new NAudioSourceStream(waveStream)); } else if (FFmpegSourceStream.WaveProxySuggested(fileInfo)) { Console.WriteLine("File format with known seek problems, creating proxy file..."); return(TryOpenSourceStream(FFmpegSourceStream.CreateWaveProxy(fileInfo))); } else { try { return(new FFmpegSourceStream(fileInfo)); } catch (FFmpegSourceStream.FileNotSeekableException) { /* * This exception gets thrown is a file is not seekable and therefore cannot * provide all the functionality that is needed for an IAudioStream, although * the problem could be solved by creating a seek index. See FFmpegSourceStream * for further information. * * For now, we create a WAV proxy file, because it is easier (consumes * additional space though). */ Console.WriteLine("File not seekable, creating proxy file..."); return(TryOpenSourceStream(FFmpegSourceStream.CreateWaveProxy(fileInfo))); } catch (DllNotFoundException) { Console.WriteLine("Cannot open file through FFmpeg: DLL missing"); } catch { // file probably unsupported Console.WriteLine("unsupported file format"); } } return(null); }