dshandler.cs

来自「这是网上下载的很好的串口发短信的程序! 是用VC++来做的」· CS 代码 · 共 76 行

CS
76
字号
using System;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;
using Buffer = Microsoft.DirectX.DirectSound.SecondaryBuffer;

namespace DDGameHelper
{
	/// <summary>
	/// DSHandler 现在还有问题。须向 DDHandler 一样,为每种声音建立 SecondBuffer 并播放,而非重复载入
	/// </summary>
	public class DSHandler
	{
		private SecondaryBuffer ApplicationBuffer = null;
		private Device ApplicationDevice = null;
		private string PathSoundFile = string.Empty;
		private Form _ownerForm;

		public DSHandler(Form ownerForm)
		{
			_ownerForm=ownerForm;
		}

		public bool Init(ref string msg)
		{
			ApplicationDevice = new Device();
			try
			{
				ApplicationDevice.SetCooperativeLevel(_ownerForm, CooperativeLevel.Priority);
			}
			catch
			{
				return false;
			}
			return true;
		}
		public void Stop()
		{
			if(null != ApplicationBuffer)
				ApplicationBuffer.Stop();
		}

		public void Play()
		{
			if(null != ApplicationBuffer)
				ApplicationBuffer.Play(0, BufferPlayFlags.Default);
		}

		public bool LoadSoundFile(string name)
		{
			try
			{
				ApplicationBuffer = new SecondaryBuffer(name, ApplicationDevice);
			}
			catch(SoundException)
			{
				return false;
			}
			return true;
		}
		public bool LoadSoundFile(System.IO.Stream s)
		{
			try
			{
				ApplicationBuffer = new SecondaryBuffer(s, ApplicationDevice);
			}
			catch(SoundException)
			{
				return false;
			}
			return true;
		}

	}
}

⌨️ 快捷键说明

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