C#中用API實(shí)現(xiàn)MP3等音頻文件的播放類
public void StopT()
{
TemStr = ;
TemStr = TemStr.PadLeft(128,Convert.ToChar( ));
ilong = APIClass.mciSendString(close media, TemStr, 128, 0);
ilong = APIClass.mciSendString(close all, TemStr, 128, 0);
mc.state = State.mStop ;
}
public void Puase()
{
TemStr = ;
TemS
ilong = APIClass.mciSendString(pause media, TemStr, TemStr.Length, 0);
mc.state = State.mPuase ;
}
private string GetCurrPath(string name)
{
if(name.Length 1) return ;
name = name.Trim();
name = name.Substring(0,name.Length-1);
return name;
}
//總時(shí)間
public int Duration
{
get
{
durLength = ;
durLength = durLength.PadLeft(128,Convert.ToChar( )) ;
APIClass.mciSendString(status media length, durLength, durLength.Length, 0);
durLength = durLength.Trim();
if(durLength == ) return 0;
return (int)(Convert.ToDouble(durLength) / 1000f);
}
}
//當(dāng)前時(shí)間
public int CurrentPosition
{
get
{
durLength = ;
durLength = durLength.PadLeft(128,Convert.ToChar( )) ;
APIClass.mciSendString(status media position, durLength, durLength.Length, 0);
mc.iPos = (int)(Convert.ToDouble(durLength) / 1000f);
return mc.iPos;
}
}
}
public class APIClass
{
[DllImport(kernel32.dll, CharSet = CharSet.Auto)]
public static extern int GetShortPathName (
string lpszLongPath,
string shortFile,
int cchBuffer
);
[DllImport(winmm.dll, EntryPoint=mciSendString, CharSet = CharSet.Auto)]
public static extern int mciSendString (
string lpstrCommand,
string lpstrReturnString,
int uReturnLength,
int hwndCallback
);
}
}
評(píng)論