Solved

Playing a music file at runtime

Posted on 2002-07-03
5
263 Views
Last Modified: 2010-05-02
Hi

I have written a small program in VB6 which is a clock that at runtime at a time previouysly entered will display a message box.  This part works OK

I would like the second part of the program to play a sound such as from a CD or off the hard drive etc - This is my problem.  I have written the following code:

Private Sub Timer1_Timer()
Label1.Caption = Time
CurrentTime = Format(Time, "hh:mm:ss")
    If CurrentTime = Text1.Text Then
    Beep   ' Sound a tone.
        MsgBox (Text2.Text), , "Alarm Clock Reminder"
        Timer1.Enabled = False
        Form1.WindowState = 0 'Restore form to original size
    End If
End Sub

I was able to make the speaker sound a 'beep' but cannot make it play a music file.  Any help much appreciated.

Regards

Mark

0
Comment
Question by:m_durnell
  • 2
  • 2
5 Comments
 
LVL 51

Accepted Solution

by:
Ryan Chong earned 50 total points
ID: 7126413
0
 
LVL 1

Author Comment

by:m_durnell
ID: 7126522
Hi Ryancys

Thanks for your comments, but what I really want is a sample of code that will "Play" a music file when a certain time is reached as the "Beep" sound does in the code in my previous comment.

For example I want the program to play the following file

c:\music\Eva1.mp3 etc

Any further help appreciated.

Regards

Mark
0
 
LVL 4

Expert Comment

by:Glowman
ID: 7127225
M,
this is a sub that I use to play a song/noise/anything.  It uses the MMcontrol that can be added in the from the toolbar components selection (Microsoft Multimedia Control 6 (SP3)).  In my example it is called Media.  This also uses a FSO object to determine if the file exists before trying to play it.  I have had a little trouble getting it to play mp3's but it handles wav files just fine.  And I think that it can play a mp3 I just didn't follow up on it.  I hope this helps you

G



Public Sub PlaySong(ByVal SongTitle As String)
       
       
    If FileTool.FileExists(SongTitle) = False Then
        Call WriteLogLine("You got lucky this time no Audio File found")
        Exit Sub
    End If
       
    With frmSample.Media
        .Notify = False
        .Wait = True
        .Shareable = False
        .DeviceType = "waveaudio"
        .FileName = SongTitle
        .Command = "open"
        .Command = "play"
    End With
   
End Sub
0
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 7131269
Try use Sleep api to pause for certain period?

Declare Sub Sleep Lib "kernel32" Alias "Sleep" ( _
           ByVal dwMilliseconds As Long _
)

http://www.allapi.net/apilist/apifunction.php?apifunction=Sleep
0
 
LVL 1

Author Comment

by:m_durnell
ID: 7139127
Ryancys

Thanks for the help with a little work I was able to get my alarm clock working properly as I intended.  I am going to try and build on it though and will ask a few more questions later in another section.

All the best

Mark
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro which automatically sends attachment to Outlook 14 78
Windows 10 start screen issues 9 55
How to hault or freeze parent form when a 2d form is open in vb6 3 40
vbModal 12 57
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question