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
{
///
/// 声音播放类
///
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;
///
/// 播放方法
///
/// 声音文件名(不包括目录)
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);
}
}
}
}