Okay, so I am trying to make an alarm clock program for computer, to familiarize myself with C#.
What I need help with, is I have the dateTimePicker tool for setting the alarm, and I have a label for displaying the current time.
My coding problem, as it were, is that I cannot figure out how to make the label display the current time, or how to get my program to play the music when the time comes around. I already have the ability to open a file, and have set the file filters for WAV, WMA, MP3, MP4, and MIDI files. so, my program can open files, but of course, at this moment, it cannot use them.
Any help would be greatly appreciated.

Time
ClaudiaHelpOnVSTO
maverick786us
hmmm...this is not good..I thought one of the purposes of a language was to create new ways to do things, not to limit...
Couldn't I create a class to play other media files in some way... Or something................to get around the net 2.0 limits
Otherwise, I guess at the alarm's time, my alarm program could open up a playlist or any other media file in WMP 10 or 11..........
kanjo
Buruburu
KipK
is it source code, or like reference...
eh, I'm sure if it' on the net, there's explanations to it or something...I hope
kangalert
however, I can't get the dateTime control to set a time--it only sets a date. In proprties, it's value shows the current date and time, but when I select another date, say, tomorrow, I can't set a time.
thanks again.
Clabab
ianpender
Man, I gotta hit that C# book I bought, and read the whole thing...
metz-
Oh it will let you set a time if you give it the appropriate values set in the properties.
You may need to set it to show a custom format. So.... in the "custom format" property:
dd/MM/yyyy hh:mm:ss
and set the "Format" property to custom
does this work
lvance1611a
to play the audio, in .NET 2.0 there is a class that will play audio but only wave files. For MP3, I guess you would have to either launch an external player to play the file or embed the WMP SDK into your application to play the file, which allows you to play any media format WMP supports.
to play wave files in .NET 2.0, import the System.Media namespace and use the SoundPlayer class, giving it the location and filename of the wave file, then use the "Play()" method to play the file
garimell
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace AudioPlay
{
public static class AudioPlayer
{
[DllImport("winmm.dll")]
public static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
[DllImport("kernel32")]
public static extern int GetShortPathName(string lpszLongPath, [Out] StringBuilder lpszShortPath, int cchBuffer);
private static string toShortFilename(string longFilename)
{
StringBuilder shortNameBuffer = new StringBuilder(256);
int bufferSize = shortNameBuffer.Capacity;
int result = GetShortPathName(longFilename, shortNameBuffer, bufferSize);
return shortNameBuffer.ToString();
}
public static void Play(string Filename)
{
// Get short filename of the provided file
string tmpFilename = toShortFilename(Filename);
mciSendString("Close SND", "0", 0, 0);
mciSendString("Open " + tmpFilename + " Alias SND", "0", 0, 0);
mciSendString("Play SND", "0", 0, 0);
}
public static void Stop()
{
mciSendString("Stop SND", "0", 0, 0);
}
}
}
Josh Smith
well there will be ways for you to do it but it will take time and too advanced, .NET supports "raw" stuff and after all, it is development :-)
you can probably create your own engine using DirectX to play MP3 but best not to "reinvent" the wheel. using the WMP SDK in your own project is perfect - there's always something there you can include in your own project to do something that doesnt exist by default.
Mayer Thomas
use a timer control and create an interval of say, every minute (1000 milliseconds) and enable it. This will tick every minute and on every tick, check the current time (DateTime.Now) compared with the time set (which should also be set into a DateTime variable for ease of use when comparing) Also in this event you would set the label to the current time:
this.theLabel.Text = DateTime.Now.ToString();
or just to set the time:
this.theLabel.Text = DateTime.Now.ToString("HH:mm:ss");
simple logic when checking time:
if DateTime.Now Equals set DateTime
{ ... play file ... }
does this help
Matty1989
Because what I was thinking, I have a button for setting the time, and for its click event handler, I should maybe use an if statement, like if the lbTime's text equals the dateTimepickers value, then it would play the song.....
I just need the coding
Thanks again.