I have two school age children, both learning and/or practicing their multiplication tables. I wrote this program to help them practice their multiplication tables in a fun way and focus on specific tables as needed. To help it be more fun, I wanted it to play music in the background and provide good A/V feedback based on correct or incorrect responses. I found lots of applications out there that does this sort of thing, but usually, they were something to buy or web based applications. I wanted something that was customizable, and could run locally without worrying with a browser or an Internet connection. I also wanted an application that could run easily from the numeric keypad while practicing – these were especially important since the target audience was younger children.
I had never attempted to put background music in an application, so I tinkered with several options. In the end, I went with embedding a Windows Media Player control into the application (see Embedding Windows Media Player below to see how). It was flexible, and natively supported a large variety of musical formats.
Using the Windows Media Player Control
The actual documentation of the Windows Media Player Control can be found on MSDN. I’ll focus on the properties I needed in this simple application.
The media player control has a
settings property that allows access to several playing attributes (e.g., auto-start, play count, and volume). The following code shows how these were applied:
.autoStart = False
.playCount = Integer.MaxValue
.volume = 10
.URL = Application.StartupPath & "\Audio\BackgroundJam.wma"
Note that I simply set the play count to the maximum integer value to, in effect, create an endless playing loop for the music. Volume was set to 10, nice and low for background music - but not too distracting.
To play and pause the music, you access the
Ctlcontrols property as follows:
Private Sub StartBackgroundMusic()
If m_backgroundMusicEnabled Then
.currentPosition = 0
Private Sub StopBackgroundMusic()
Embedding the Windows Media Player
To embed the Windows Media Player control into your own application, you must click “Choose Items” from the Visual Studio toolbox (visible when a form is in design mode), then select the “COM Components” tab – be patient, this may take a while to load. If you have Windows Media Player installed on your system, there should be a COM component labeled “Windows Media Player” with a path such as C:\Windows\system32\wmp.dll; check this item, and click OK. If all you want is music in your application (i.e., not video), make sure and set the
Visible property of the control to
Points of Interest
There is a class provided (ConfigurationSettings.vb) in the source code that simplifies the usage of saving and retrieving settings from a local configuration file. It automatically casts settings to and from
Integer values; here is an example of its usage:
Private Sub PracticeTool_FormClosing(ByVal sender As Object, ByVal e As _
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
m_countDownTimer.Enabled = False
BooleanSetting("RandomTestOrder") = m_randomTestOrder
BooleanSetting("IncludeZeroInRange") = m_includeZeroInRange
BooleanSetting("AudioFeedbackEnabled") = m_audioFeedbackEnabled
BooleanSetting("BackgroundMusicEnabled") = m_backgroundMusicEnabled
BooleanSetting("BackgroundMusicAlwaysOn") = m_backgroundMusicAlwaysOn
IntegerSetting("CorrectAnswerDelay") = m_correctAnswerDelay
IntegerSetting("IncorrectAnswerDelay") = m_incorrectAnswerDelay
IntegerSetting("CountDownTime") = m_countDownTime
BooleanSetting("WrongAnswerOnTimeout") = m_wrongAnswerOnTimeout
Setting("PracticeNumbers") = Numbers.Text
Setting("PracticeRange") = Range.Text
Setting("ChildsName") = m_childsName
Generally, this application should be a good example for anyone getting started with VB.NET.
Using the Application
Assuming you actually got to this page to simply use this program for your own child, no worries – usage should be simple enough. All you need to do is just deploy the binaries into their own folder and run the executable. Watch for tool-tips for help, and adjust the options as needed. Again, the application uses the Windows Media Player control internally, so having Windows Media Player installed is a prerequisite. There are several options to tailor the usage to an individual child’s needs:
Additionally, the audio used by the program can be easily changed in the "Audio" folder to fit your child's interests a little better - this includes a "background jam" to keep things interesting. Simply override the existing files with the sound files of your preference, just make sure and use the same file names.