예제 #1
0
        private Sound LoadNextSound(LowLevelSystem system)
        {
            if (++_soundIndex >= _sounds.Length)
            {
                _soundIndex = 0;
            }

            string fileName = GetContentPath(_sounds[_soundIndex]);

            Console.WriteLine("Loading {0}", _sounds[_soundIndex]);

            var sound = system.CreateStream(name: fileName, mode: Mode.Default);

            if (_currentSound.HasValue)
            {
                // Because of some difference between Mono and CLR we can't dispose the sound here
                // while being called from the callback. The sound has finished playing, but for some
                // reason Mono will crash in the callback handler from the native side if we dispose here.
                // Putting it in a list to be disposed later worked good on Mono. CLR didn't have this issue.
                _disposeList.Add(_currentSound.Value);
            }

            _currentSound = sound;

            return(sound);
        }
        public void TestMethod1()
        {
            using (var system = new LowLevelSystem(preInit: a => { a.Output = OutputMode.NoSound; }))
            {
                //Load a sound to play
                var sound = system.CreateStream(name: "Content/Front_Center.wav", mode: Mode.Default);

                // Begin playing the sound
                var channel = system.PlaySound(sound, null, false);

                bool flag = true;

                channel.SetCallback((type, data1, data2) =>
                {
                    if (type == ChannelControlCallbackType.End)
                    {
                        //Now that the sound is done, dispose it
                        //With issue #23 this should crash on mono
                        sound.Dispose();

                        flag = false;
                    }
                });

                //Loop until the flag is set to false
                while (flag)
                {
                    system.Update();
                }
            }
        }