コード例 #1
0
        public static SoundEffect LoadSoundEffect(string path)
        {
            SoundEffect soundEffect = null;


            if (path.EndsWith(".wav"))
            {
                FileStream stream = new FileStream(path, FileMode.Open);
                try
                {
                    soundEffect = SoundEffect.FromStream(stream);
                }
                catch (Exception e)
                {
                    stream.Close();
                }
                stream.Close();
                stream.Dispose();
            }
            else
            {
                soundEffect = OggLoader.Load(path);
            }

            if (soundEffect == null)
            {
                SMonitor?.Log("Failed to load: " + path, LogLevel.Error);
            }

            return(soundEffect);
        }
コード例 #2
0
        private void addMusic(string path, MusicItem music)
        {
            Monitor.Log("Loading " + music.File + " ...", LogLevel.Info);

            SoundEffect soundEffect = null;

            string orgPath = path;

            path = config.Convert ? path.Replace(".ogg", ".wav") : path;

            if (config.Convert && !File.Exists(path))
            {
                Convert(orgPath);
            }

            if (path.EndsWith(".wav"))
            {
                soundEffect = SoundEffect.FromStream(new FileStream(path, FileMode.Open));
            }
            else
            {
                soundEffect = OggLoader.Load(path);
            }

            Monitor.Log(music.File + " Loaded", LogLevel.Trace);
            string[] ids = music.Id.Split(',').Select(p => p.Trim()).ToArray();
            foreach (string id in ids)
            {
                Music.Add(new StoredMusic(id, soundEffect, music.Ambient, music.Loop, music.Conditions));
            }
        }
コード例 #3
0
        /*********
        ** Public methods
        *********/
        /// <summary>Load content from SMAPI's content API with added support for audio files.</summary>
        /// <typeparam name="T">The expected data type.</typeparam>
        /// <param name="content">The content manager to extend.</param>
        /// <param name="key">The asset key to fetch (if the <paramref name="source"/> is <see cref="ContentSource.GameContent"/>), or the local path to a content file relative to the mod folder.</param>
        /// <param name="source">Where to search for a matching content asset.</param>
        /// <remarks>Since this is just a quick prototype, this doesn't handle caching and such for audio files.</remarks>
        public static T ExtendedLoad <T>(this IContentHelper content, string key, ContentSource source = ContentSource.ModFolder)
        {
            // ignore non-audio files
            if (source != ContentSource.ModFolder || key?.Trim().EndsWith(".ogg", StringComparison.InvariantCultureIgnoreCase) != true)
            {
                return(content.Load <T>(key, source));
            }

            // get mod file
            key = content.NormalizeAssetName(key);
            FileInfo file = content.GetPrivateField <object>("ModContentManager").InvokePrivateMethod <FileInfo>("GetModFile", key);

            if (!file.Exists)
            {
                return(content.Load <T>(key, source));
            }

            // load unpacked audio file
            if (typeof(T) != typeof(IModCue) && typeof(T) != typeof(ICue))
            {
                throw new ContentLoadException($"Failed loading asset '{key}' from content manager: can't read file with extension '{file.Extension}' as type '{typeof(T)}'; must be type '{typeof(ICue)}' or '{typeof(IModCue)}'.");
            }
            SoundEffect effect = OggLoader.Load(file.FullName);

            return((T)(object)new SoundEffectCue(key, effect));
        }
コード例 #4
0
        public IAudioBuffer LoadAsBuffer(IFile file)
        {
            var pcm    = new OggLoader().Load(file);
            var buffer = this.Factory.NewAudioBuffer();

            buffer.FillWithPcm(pcm);
            return(buffer);
        }
コード例 #5
0
        private void addMusic(string path, MusicItem music)
        {
            Monitor.Log("Loading " + music.File + " ...", LogLevel.Info);
            SoundEffect soundEffect = OggLoader.Load(path);

            Monitor.Log(music.File + " Loaded", LogLevel.Trace);
            string[] ids = music.Id.Split(',').Select(p => p.Trim()).ToArray();
            foreach (string id in ids)
            {
                Music.Add(new StoredMusic(id, soundEffect, music.Ambient, music.Loop, music.Conditions));
            }
        }
コード例 #6
0
        public static SoundEffect LoadSoundEffect(string path)
        {
            int         c           = 0;
            Exception   le          = null;
            SoundEffect soundEffect = null;


            if (path.EndsWith(".wav"))
            {
                while (soundEffect == null && c < ti)
                {
                    FileStream stream = new FileStream(path, FileMode.Open);
                    try
                    {
                        soundEffect = SoundEffect.FromStream(stream);
                    }
                    catch (Exception e)
                    {
                        stream.Close();
                        c++;
                        le = e;
                        Thread.Sleep(slp);
                    }
                    stream.Close();
                    stream.Dispose();
                }
            }
            else
            {
                while (soundEffect == null && c < ti)
                {
                    try
                    {
                        soundEffect = OggLoader.Load(path);
                    }
                    catch (Exception e)
                    {
                        c++;
                        le = e;
                        Thread.Sleep(slp);
                    }
                }
            }

            return(soundEffect);
        }