⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sound.cs

📁 一个用java设计的推箱子的程序。很不错的。呵呵
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using nBASS;

namespace PushBox
{
    class Sound : IDisposable
    {
        private static nBASS.BASS soundDevice = null;


        private AdvancedChannel soundBuffer = null;





        public Sound(System.Windows.Forms.Form windowHandle)
        {

            if (Sound.soundDevice == null)
            {

                soundDevice = new nBASS.BASS();
                Sound.soundDevice.BeginInit();
                soundDevice.Device = "Default";
                soundDevice.Frequency = 44100;
                soundDevice.MusicVolume = 700;
                soundDevice.ParentForm = windowHandle;
                soundDevice.SampleVolume = 100;
                soundDevice.SetupFlags = nBASS.DeviceSetupFlags.Default;
                soundDevice.StreamVolume = 100;
                soundDevice.EndInit();
            }
        }


        ~Sound()
        {
            // Call the dispose method.
            Dispose();
        }

        public void Dispose()
        {

            try
            {
                soundBuffer.Dispose();
            }
            catch
            {
            }

            soundBuffer = null;


        }

        /// <summary>
        /// Method that loads a sound file to the buffer.
        /// </summary>
        /// <param name="fileName">Name of the file to be loaded.</param>
        /// <returns>True if the file was successful loaded, or false if it wasn't.</returns>
        public void Load(string fileName)
        {
            // Holds the result for if the file was successful loaded or not.


            // Tries to open the sound file.
            try
            {
                // Opens the sound file.
                soundBuffer = Sound.soundDevice.LoadStream(fileName, 0, 0, 0);
                // If there was no error, sets the result as true.

            }
            catch
            {

            }

            // Returns the result.

        }

        //		public void AddVolume()
        //		{
        //			Sound.soundDevice .MusicVolume+=100;
        //			Sound.soundDevice.SampleVolume+=100;
        //			Sound.soundDevice.StreamVolume +=100;
        //		}

        /// <summary>
        /// Method that plays the sound in the current buffer.
        /// </summary>
        public void Play()
        {
            soundBuffer.Play(true, StreamPlayFlags.Default);
        }

        public void LoopPlay()
        {
            soundBuffer.Play(true, StreamPlayFlags.Loop);
        }

        public void Stop()
        {
            soundBuffer.Stop();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -