日期:2014-05-17  浏览次数:20947 次

C#用system.media播放背景音乐总是显示该文件不是波形文件
如题,C#用system.media播放背景音乐总是显示该文件不是波形文件

------解决方案--------------------
可能真不是波形文件吧
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);
}
 }
}

------解决方案--------------------
用千千静听将那个文件转换一下