Solved

Playing a music file at runtime

Posted on 2002-07-03
5
258 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 49

Accepted Solution

by:
Ryan Chong earned 50 total points
Comment Utility
0
 
LVL 1

Author Comment

by:m_durnell
Comment Utility
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
Comment Utility
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 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now