?? sound.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();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -