ما هو الكود اللازم لتشغيل ملف موسيقي في فورم c# وهل نستطيع تشغيل الملف بغير صيغة wav
تشغيل ملف موسيقي في فورم c#
السلام عليكم
لقراءة ملفات الـ wav :
System.Media.SoundPlayer player = new SoundPlayer(); player.SoundLocation = "c:\\test.wav"; player.LoadAsync(); player.PlayLooping(); //asynchronous (loop)playing in new thread Thread.Sleep(5000); player.Stop();
و ملفات الـ MP3 :
// Play MP3 files
public class Player
{
private string _command;
private bool isOpen;
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand,StringBuilder strReturn,int iReturnLength, IntPtr hwndCallback);
public Player()
{
}
public void Close()
{
_command = "close MediaFile";
mciSendString(_command, null, 0, IntPtr.Zero);
isOpen=false;
}
public void Open(string sFileName)
{
_command = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";
mciSendString(_command, null, 0, IntPtr.Zero);
isOpen = true;
}
public void Play(bool loop)
{
if(isOpen)
{
_command = "play MediaFile";
if (loop)
_command += " REPEAT";
mciSendString(_command, null, 0, IntPtr.Zero);
}
}
}C++ and Java, say, are presumably growing faster than plain C, but I bet C will still be around. ― Dennis Ritchie
~OoO~________--------------------------------------------________~OoO~
من مواضيعي :
هل بالإمكان أخي الكريم أن تشرح قليلاً هذا الكود ؟