Hello dears.
I need to play a music in my projects background.
I did such below but it does not work.
what is problem please?
class PlayMusic
{
private string cmd;
private bool isOpen;
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand,StringBuilder strReturn,int iReturnLength, IntPtr hwndCallback);
public void Close()
{
cmd = "close MediaFile";
mciSendString(cmd, null, 0, IntPtr.Zero);
isOpen = false;
}
public void Open(string sFileName)
{
cmd = "open "+ sFileName +" type mpegvideo alias MediaFile";
mciSendString(cmd, null, 0, IntPtr.Zero);
isOpen = true;
}
public void Play(bool loop)
{
if (isOpen)
{
cmd = "play MediaFile";
mciSendString(cmd, null, 0, IntPtr.Zero);
if (loop)
cmd = " REPEAT";
mciSendString(cmd, null, 0, IntPtr.Zero);
}
}
}
my headers are :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
and my playing action is:
PlayMusic pm = new PlayMusic();
pm.Open("c:\test.mp3");
pm.Play(true);
when I do it it do nothing.I dont know what is the probleme.
Thanks if help me dears.