如题,C#用system.media播放背景音乐总是显示该文件不是波形文件
解决方案 »
- mdi窗体中,如果一子窗体已打开,点击按钮显示该窗体到最前会有明显的放大过程,闪眼睛,哪们高手有办法
- C#如何使用雙核?
- 如何将dataset中的table导入数据库,前提是不知道该table的结构,而且数据库中也没有对应的表。
- c#窗体值传递问题
- 关于UPdate更新数据库的问题。还请各位热心帮忙解决,先谢了!!!!
- 关于C#右键菜单项
- 一个关于控制textbox输入内容的小问题,请大虾指点
- 堆中的数据 如何存取 ? int 数据应该 放栈 中吧 ?堆大小 ? 栈大小 ?
- 请问如何把桌面的所有窗口最大化?
- 问一个 "非技术问题" , 进来看看好吗 ?
- 一个很深的问题,多线程相关
- 最后一个C#正则问题了,搞了半天搞不对啊。
system.media只支持波形文件
你可以换其他方式播放背景音乐using System;
using System.Runtime.InteropServices;
using System.ComponentModel;namespace Common
{
/// <summary>
/// clsPlaySound 的摘要说明。
/// </summary>
public class clsPlaySound
{
protected const int SND_SYNC = 0x0;
protected const int SND_ASYNC = 0x1;
protected const int SND_NODEFAULT = 0x2;
protected const int SND_MEMORY = 0x4;
protected const int SND_LOOP = 0x8;
protected const int SND_NOSTOP = 0x10;
protected const int SND_NOWAIT = 0x2000;
protected const int SND_ALIAS = 0x10000;
protected const int SND_ALIAS_ID = 0x110000;
protected const int SND_FILENAME = 0x20000;
protected const int SND_RESOURCE = 0x40004;
protected const int SND_PURGE = 0x40;
protected const int SND_APPLICATION = 0x80; [DllImport("Winmm.dll", CharSet=CharSet.Auto)]
protected extern static bool PlaySound(string strFile, IntPtr hMod, int flag ); //播放声音函数
//strSoundFile --- 声音文件
//bSynch --- 是否同步,如果为True,则播放声音完毕再执行后面的操作,为False,则播放声音的同时继续执行后面的操作
public static bool PlaySoundFile(string strSoundFile, bool bSynch)
{
if(!System.IO.File.Exists(strSoundFile))
return false;
int Flags;
if(bSynch)
Flags = SND_FILENAME | SND_SYNC;
else
Flags = SND_FILENAME | SND_ASYNC; return PlaySound(strSoundFile, IntPtr.Zero, Flags);
}
}
}
[DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
public static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
mciSendString("Open " + path + " alias wavType", null, 0, 0);//path是声音文件路径
mciSendString("Play wavType", null, 0, 0);