public static SoundEffect GetSound(string path) { path = NormalizePath(path); SoundEffect sound = null; SoundCache.TryGetValue(path, out sound); return(sound); }
private static MemoryStream GetSoundStream(string soundName) { byte[] data; if (!SoundCache.TryGetValue(soundName, out data)) { var moduleName = Assembly.GetExecutingAssembly().GetName().Name; var resourceLocation = $"pack://application:,,,/{moduleName};component/Resources/Sounds/{soundName}"; var stream = Application.GetResourceStream(new Uri(resourceLocation)); if (stream == null) { return(null); } data = new byte[stream.Stream.Length]; stream.Stream.Read(data, 0, data.Length); SoundCache[soundName] = data; } return(new MemoryStream(data)); }