Kod:
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
public string Pcommand;
public bool isOpen;
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
}
string alarm;
int cs = 0;
private void timer1_Tick(object sender, EventArgs e)
{
label3.Text = DateTime.Now.ToLongTimeString();
if (label3.Text == alarm)
{
MessageBox.Show("Alarm Çalıyor");
Pcommand = "open \"" + textBox1.Text + "\" type mpegvideo alias MediaFile";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
isOpen = true;
Play(true);
cs = cs + 1;
if (cs.ToString() == textBox5.Text.ToString())
{
Pcommand = "close MediaFile";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
isOpen = false;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Media File(*.mpg,*.dat,*.avi,*.wmv,*.wav,*.mp3)|*.wav;*.mp3;*.mpg;*.dat;*.avi;*.wmv";
openFileDialog1.ShowDialog();
textBox1.Text = openFileDialog1.FileName;
}
private void button2_Click(object sender, EventArgs e)
{
Pcommand = "open \"" + textBox1.Text + "\" type mpegvideo alias MediaFile";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
isOpen = true;
Play(true);
}
private void button3_Click(object sender, EventArgs e)
{
Pcommand = "close MediaFile";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
isOpen = false;
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
}
public void Play(bool loop)
{
if (isOpen)
{
Pcommand = "play MediaFile";
if (loop)
Pcommand += " REPEAT";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
}
}
private void button5_Click(object sender, EventArgs e)
{
alarm = Convert.ToString(textBox2.Text + ":" + textBox3.Text + ":" + textBox4.Text);
}