In the last article, I added a functional interface for browsing local WAV Files with slight changes.
ProgramCode
View code
Using System;
Using System. Windows. forms;
Using System. Media;
Namespace Alarmclock
{
Public Partial Class Form1: Form
{
Public Form1 ()
{
Initializecomponent ();
}
Soundplayer player = New Soundplayer ();
Private Void Form1_load ( Object Sender, eventargs E)
{
Timer1.start ();
// Bind to ComboBox
For ( Int I = 0 ; I <= 23 ; I ++ )
{
Cmbhour. Items. Add (I );
}
For ( Int J = 0 ; J < 60 ; J ++ )
{
Cmbminute. Items. Add (j );
}
// Bind ringtone
Cmbring. Items. Add ( " BBK music .wav " );
Cmbring. Items. Add ( " Background Music .wav " );
}
Private Void Timereffectick ( Object Sender, eventargs E)
{
Timer1.interval = 1000 ;
Lblnow. Text = Datetime. Now. tostring ();
}
Private Void Btnpreview_click ( Object Sender, eventargs E)
{
Playjudge ();
}
/// <Summary>
/// Determine whether the local playback is provided by the system
/// </Summary>
Private Void Playjudge ()
{
If (Cmbring. Text = "" && Txtupload. Text = "" )
{
MessageBox. Show ( " Select system ringtones or local ringtones " );
Return ;
}
If (Cmbring. Text = "" | Txtupload. Text ! = "" )
{
Playsound (txtupload. Text );
}
If (Cmbring. Text ! = "" | Txtupload. Text = "" )
{
Playsound (cmbring. Text );
}
}
/// <Summary>
/// Play WAV audio files
/// </Summary>
Private Void Playsound ( String Path)
{
// Use the new instance point soundlocation to specify the name of the music to be played.
Player. soundlocation = Path; // (Put the playing music in the application DEBUG directory)
Player. Load ();
// Play Music
Player. Play ();
}
Private Void Btnopen_click ( Object Sender, eventargs E)
{
If (Cmbhour. Text = "" && Cmbminute. Text = "" )
{
MessageBox. Show ( " No alert time set " );
Return ;
}
Timer2.start ();
}
Private Void Timer2_tick ( Object Sender, eventargs E)
{
Timer2.interval = 1000 ;
String H = Cmbhour. text;
String M = Cmbminute. text;
String Nowh = Datetime. Now. Hour. tostring ();
String Nowm = Datetime. Now. Minute. tostring ();
If (H = Nowh && M = Nowm)
{
Playjudge ();
// Stop threads after enabling
Timer2.stop ();
}
}
Private Void Btnstop_click ( Object Sender, eventargs E)
{
Timer2.stop ();
Player. Stop ();
}
/// <Summary>
/// Browse local ringtones
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private Void Button#click ( Object Sender, eventargs E)
{
// Determine whether the "open file dialog box" is opened"
If (Openfiledialog1.showdialog () = Dialogresult. OK)
{
String File = Openfiledialog1.filename;
If (File ! = Null )
{
// Determine whether the uploaded file is a WAV ringtone
// D: \ winformtest \ alarmclcok \ myclock \ bin \ debug \ BBK .wav
String Fileextend = File. substring (file. lastindexof ( " . " ) + 1 ). Tostring (). tolower ();
If (Fileextend ! = " Wav " )
{
MessageBox. Show ( " Select a WAV file. " );
Return ;
}
Txtupload. Text = File;
}
}
}
}
}