You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Mesnac.Action
{
/// <summary>
/// 声音播放类
/// </summary>
public class MediaPlayerEx
{
private static string SoundFileDir = "Data\\Sound";
[DllImport("winmm.dll")]
public static extern bool PlaySound(string pszSound, int hmod, int fdwSound);
public const int SND_FILENAME = 0x00020000;
public const int SND_ASYNC = 0x0001;
/// <summary>
/// 播放方法
/// </summary>
/// <param name="fileName">声音文件名(不包括目录)</param>
public static void Play(string fileName)
{
string fullPath = Path.Combine(Application.StartupPath, SoundFileDir, fileName);
if (File.Exists(fullPath))
{
//MediaPlayer.MediaPlayer player = new MediaPlayer.MediaPlayer();
//player.FileName = fullPath;
//player.Play();
PlaySound(fullPath, 0, SND_ASYNC | SND_FILENAME);
}
else
{
ICSharpCode.Core.LoggingService.Warn("无此声音文件:" + fullPath);
}
}
}
}