Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to create an alarm using c#. I wrote tahat code but I want to add mp3 file. How can I do this. Please help me

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;
namespace aLARM_cLOCK
{
    public partial class frmAlarm : Form
    {
      
      
        public frmAlarm()
        {
            InitializeComponent();
        }
        OpenFileDialog opd = new OpenFileDialog();
        private void frmAlarm_Load(object sender, EventArgs e)
        {

        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            if (txtRoad.Text !="" || txtTime.Text !="")
            {
                timer1.Start();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            string now = DateTime.Now.ToLongTimeString();
            string WantedTime = txtTime.Text;
            if (now==WantedTime)
            {
                SoundPlayer pleyer = new SoundPlayer();
                pleyer.SoundLocation = opd.FileName;
                pleyer.Play();
                MessageBox.Show(txtMessage.Text);
            }
        }

        private void btnRoad_Click(object sender, EventArgs e)
        {
            opd.Filter = "file of music | '. wav'";
            opd.ShowDialog();
            txtRoad.Text = opd.FileName;
            
        }

        private void btnStop_Click(object sender, EventArgs e)
        {  
            timer1.Stop();
         
        }
    }
}
Posted
Updated 2-Sep-14 2:55am
v2

Hi,

Try this.

C#
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();

wplayer.URL =  "mp3 URL";
wplayer.controls.play();


Interop.WMPLib.dll You can download from the following url, and add dll reference to your project.

http://www.dllme.com/dll/download/22969/Interop.WMPLib.dll[]
 
Share this answer
 
v2
Comments
goksurahsan 2-Sep-14 9:22am    
Error 1 The type or namespace name 'WMPLib' could not be found (are you missing a using directive or an assembly reference?) C:\Users\faikbatan\Desktop\Alarm Clock\Alarm Clock\Alarm.cs 53 13 Alarm Clock
goksurahsan 2-Sep-14 9:23am    
I took this error
Renju Vinod 3-Sep-14 0:13am    
Download Interop.WMPLib.dll from this link
http://www.dllme.com/dll/download/22969/Interop.WMPLib.dll
and add that dll reference to your project.
goksurahsan 3-Sep-14 4:17am    
thank you for helping
Renju Vinod 3-Sep-14 4:59am    
Please accept the solution if its works for you.
Here is good example with sample code

Use a timer to create a simple alarm application[^]
 
Share this answer
 
Comments
goksurahsan 3-Sep-14 4:29am    
yes, here is good example. But it doesn't have thing which I wanted. I want to change opd.Filter = "file of music | '. wav'"; this code to mp3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900