OpenRA.Sound.LoadSound C# (CSharp) Method

LoadSound() private method

private LoadSound ( ISoundLoader loaders, IReadOnlyFileSystem fileSystem, string filename ) : ISoundSource
loaders ISoundLoader
fileSystem IReadOnlyFileSystem
filename string
return ISoundSource
        ISoundSource LoadSound(ISoundLoader[] loaders, IReadOnlyFileSystem fileSystem, string filename)
        {
            if (!fileSystem.Exists(filename))
            {
                Log.Write("sound", "LoadSound, file does not exist: {0}", filename);
                return null;
            }

            using (var stream = fileSystem.Open(filename))
            {
                ISoundFormat soundFormat;
                foreach (var loader in Game.ModData.SoundLoaders)
                {
                    stream.Position = 0;
                    if (loader.TryParseSound(stream, out soundFormat))
                        return soundEngine.AddSoundSourceFromMemory(
                            soundFormat.GetPCMInputStream().ReadAllBytes(), soundFormat.Channels, soundFormat.SampleBits, soundFormat.SampleRate);
                }
            }

            throw new InvalidDataException(filename + " is not a valid sound file!");
        }