Introduction
In this article, I am using Multimedia MCI
control to make animation as Timer
control. You can use StatusUpdate
Event to do this. The StatusUpdate
Event occurs automatically at intervals which you give to the UpdateInterval
property suitable value > 0
exactly as Timer
Control Interval.
Background
With Multimedia MCI
Control, you must know that the StatusUpdate
Event allows an application to update the display to inform the user about the status of the current MCI
device as Position
, Length
, and Mode
. You can give the UpdateInterval
property any positive value (in milliseconds). If this value is small, the display is fast, if value is large, the display is slow, but if the value is 0
, no StatusUpdate
events occur.
My form has some controls:
mciWave
(MMControl
), not Visible ImageList1
includes 30 images ImageList2
includes 6 images DancePic
(Picture box) to hold images which ImageList2
has included MoviePic
(Picture box) to hold images which ImageList1
has included btnPlay
(Button
) to execute the (Play
) command btnPause
(Button
) to execute the (Pause
) command btnStop
(Button
) to execute the (Stop
) command btnOpen
(Button
) to load the music file SongName
(Label
) for file name SongTime
(Label
) for time length of file ElapsedTime
(Label
) for Elapsed time CommonDialog1
(CommonDialog
) to load music files in format (mid, mp3, wav, wma)
Using the Code
Give UpdateInterval
property the value 50 as constant in the declarations. Refer to other variables in the declarations part.
LoadMusicFile()
procedure:
mciWave.UpdateInterval = 0
With CommonDialog1
.FilterIndex = 1
.Flags = cdlOFNReadOnly Or cdlOFNFileMustExist
.CancelError = True
.FileName = ""
.Filter = "Sound Formats|*.mid;*.mp3;*.wav;*.wma|mid (*.mid)|
*.mid|mp3 (*.mp3)|*.mp3|wav (*.wav)|*.wav|wma (*.wma)|*.wma"
.DialogTitle = "Choose sound file..."
End With
CommonDialog1.ShowOpen
If Err <> 0 Then
Exit Sub
End If
MusicFile = CommonDialog1.FileName
MusicName = CommonDialog1.FileTitle
InitPlay
InitPlay()
procedure:
If Not mciWave.Mode = mciModeNotOpen
Then mciWave.Command = "Close" End If
mciWave.Command = "Open"
mciWave.TimeFormat = mciFormatMilliseconds msec = (CDbl(mciWave.Length) / 1000)
btnPlay_Click()
procedure:
mciWave.UpdateInterval = ConInterval
mciWave.Command = "Play"
btnPause_Click()
procedure:
mciWave.UpdateInterval = 0
mciWave.Command = "Pause"
btnStop_Click()
procedure:
mciWave.UpdateInterval = 0
mciWave.Command = " Stop"
mciWave_StatusUpdate()
procedure:
If mciWave.Position = mciWave.Length Then
mciWave.UpdateInterval = 0
Exit Sub
End If
CurrentValue = mciWave.Position
Value = CDbl((CurrentValue / 1000))
ElapsedTime.Caption = Format$(Value, "00:00")
Counter = Counter + 1: If Counter = 25 Then Counter = 0
If (Counter / 5) = Int(Counter / 5) Then
PicNum = Counter / 5 + 1
DancePic.Picture = ImageList2.ListImages(PicNum).Picture
End If
MasterCounter = MasterCounter + 1: If MasterCounter = 1500 Then MasterCounter = 0
If (MasterCounter / 50) = Int(MasterCounter / 50) Then
ImgNum = MasterCounter / 50 + 1
MoviePic.Picture = ImageList1.ListImages(ImgNum).Picture
End If
You can go back to source files of the project AudioPlayer
to read the complete code. For more help, you can refer to Multimedia MCI Control at Visual Basic Help.
Remarks
When extracting the AudioPlayer.zip file, you can find the source files of the project AudioPlayer
.
Last Words
I hope this article is useful and helps you to create some applications using MMControl
as Timer
. Please tell me if you have any ideas or if you find any problems. Thanks to Code Project and thanks to all.
History
- 2nd February, 2008: Initial version