Please Help New User
Please Help New User
Please Help New User
Please Help New User
Please Help New User
Please Help New User Please Help New User Please Help New User Please Help New User Please Help New User Please Help New User Please Help New User Please Help New User
Please Help New User Please Help New User
Please Help New User
Go Back  Xtreme Visual Basic Talk > > > Please Help New User


Reply
 
Thread Tools Display Modes
  #1  
Old 03-16-2004, 05:09 PM
mycomputerman mycomputerman is offline
Freshman
 
Join Date: Mar 2004
Location: United States
Posts: 31
Default Sound Problem


I am creating a "Who Wants to be a Millionaire?" game and would like to add sound files like, "Is that your final answer?" Does anyone know how to add a sound file to a form, so when a button is clicked or a form is loaded it would play using Windows Media Player?

Last edited by mycomputerman; 03-16-2004 at 09:01 PM.
Reply With Quote
  #2  
Old 03-24-2004, 10:07 AM
Abaillie's Avatar
Abaillie Abaillie is offline
Regular
 
Join Date: Jun 2003
Location: Scotland
Posts: 92
Default

hope this helps

Dim SoundInst As New SoundClass
SoundInst.PlaySoundFile("c:\cough.wav")

this of course play a wave file called cough.wav located in the root of c:
Reply With Quote
  #3  
Old 03-24-2004, 01:37 PM
Machaira's Avatar
MachairaPlease Help New User Machaira is offline
Jedi Coder

* Expert *
 
Join Date: Aug 2002
Location: Abingdon, MD
Posts: 3,438
Default

Did you forget to attach or post the SoundClass class?

You can also do:

DeclareAutoFunction PlaySound Lib "winmm.dll" _
(
ByVal lpszName AsString, ByVal hModule AsInteger, ByVal dwFlags AsInteger) AsInteger

PrivateConst SND_ASYNC = &H1 ' play asynchronously

PrivateConst SND_FILENAME = &H20000 ' name is a file name

PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

PlaySound(Application.StartupPath & "\test.wav", 0, SND_FILENAME
Or SND_ASYNC)

EndSub

Reply With Quote
  #4  
Old 03-25-2004, 03:10 AM
Abaillie's Avatar
Abaillie Abaillie is offline
Regular
 
Join Date: Jun 2003
Location: Scotland
Posts: 92
Default

yes i did, sorry


Public Class SoundClass
Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer
Public Const SND_SYNC = &H0
Public Const SND_ASYNC = &H1
Public Const SND_FILENAME = &H20000
Public Const SND_RESOURCE = &H40004

Public Sub PlaySoundFile(ByVal filename As String)
PlaySound(filename, Nothing, SND_FILENAME Or SND_ASYNC)
End Sub
Reply With Quote
  #5  
Old 03-26-2004, 03:07 PM
mycomputerman mycomputerman is offline
Freshman
 
Join Date: Mar 2004
Location: United States
Posts: 31
Default Doesn't Work

I tried what both of you suggested but neither time did the sound play. Any other ideas? Is this all the code you need or is there something else I should of added? Thanks for helping me.
Reply With Quote
  #6  
Old 03-29-2004, 01:46 AM
Abaillie's Avatar
Abaillie Abaillie is offline
Regular
 
Join Date: Jun 2003
Location: Scotland
Posts: 92
Default

I assume you put in an appropriate location where the wav file is you wanted to play?
Reply With Quote
  #7  
Old 03-29-2004, 02:37 PM
mycomputerman mycomputerman is offline
Freshman
 
Join Date: Mar 2004
Location: United States
Posts: 31
Default

Yes, but will an mp3 file format work or does it need to be a .wav?

Last edited by mycomputerman; 03-29-2004 at 02:39 PM. Reason: SPELLING ERROR
Reply With Quote
  #8  
Old 03-29-2004, 02:49 PM
mycomputerman mycomputerman is offline
Freshman
 
Join Date: Mar 2004
Location: United States
Posts: 31
Default

I would like the sound to play when the form is loaded.

This is the code I tried:


Public Class SoundClass
Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer
Public Const SND_SYNC = &H0
Public Const SND_ASYNC = &H1
Public Const SND_FILENAME = &H20000
Public Const SND_RESOURCE = &H40004

Public Sub PlaySoundFile(ByVal filename As String)
PlaySound(Application.StartupPath & "C:\Documents and Settings\daniel\My Documents\Downloads\final_answer.mp3", 0, SND_FILENAME Or SND_ASYNC)
End Sub
End Class
Reply With Quote
  #9  
Old 03-30-2004, 02:12 AM
Abaillie's Avatar
Abaillie Abaillie is offline
Regular
 
Join Date: Jun 2003
Location: Scotland
Posts: 92
Default

convert it to a wav file. You can get converters on the internet quite easy.
Reply With Quote
  #10  
Old 03-30-2004, 06:42 AM
Machaira's Avatar
MachairaPlease Help New User Machaira is offline
Jedi Coder

* Expert *
 
Join Date: Aug 2002
Location: Abingdon, MD
Posts: 3,438
Default

Problem here:

PlaySound(Application.StartupPath & "C:\Documents and Settings\daniel\My Documents\Downloads\final_answer.mp3", 0, SND_FILENAME Or SND_ASYNC)

You need to pick one way of specifying the path or another - you're using both the Application.StartupPath and a hard-coded path. Try to avoid using hard-coded paths to files if possible.
Reply With Quote
  #11  
Old 03-30-2004, 02:30 PM
mycomputerman mycomputerman is offline
Freshman
 
Join Date: Mar 2004
Location: United States
Posts: 31
Default

Abaillie: Making it .wav did not solve the problem.

Machaira: What is the hard-coded path? What would the path for the Application.StartupPath look like?


Anyone know how I would then use this to make the sound play when a form loads? Thanks again!!
Reply With Quote
  #12  
Old 03-30-2004, 04:58 PM
Iceplug's Avatar
IceplugPlease Help New User Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

If the file is located in your application's folder, then use Application.StartupPath and take out the hardcoded path "C:\Documents and Settings\daniel\My Documents\Downloads"
In Machaira's example on how you would use Application.StartupPath:
PlaySound(Application.StartupPath & "\test.wav", 0, SND_FILENAME Or SND_ASYNC)
And you can only play WAV files with PlaySound.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #13  
Old 03-31-2004, 02:16 PM
mycomputerman mycomputerman is offline
Freshman
 
Join Date: Mar 2004
Location: United States
Posts: 31
Default

How do you add a file to your Applications folder and what is the Applications folder?
Reply With Quote
  #14  
Old 03-31-2004, 02:58 PM
mycomputerman mycomputerman is offline
Freshman
 
Join Date: Mar 2004
Location: United States
Posts: 31
Default

I figured out how to add a file to the application folder.

This is the code I tryed to use to play a sound:

Public Class SoundClass
Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer
Public Const SND_SYNC = &H0
Public Const SND_ASYNC = &H1
Public Const SND_FILENAME = &H20000
Public Const SND_RESOURCE = &H40004

Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PlaySound(Application.StartupPath & "\final_answer.wav", 0, SND_FILENAME Or SND_ASYNC)
End Sub
End Class

When I tried this I got the error "Event 'Load' cannot be found." The orange section is the section that the error was aiming at. By running the program with this error, the sound did not play. Any suggestions?

Last edited by mycomputerman; 03-31-2004 at 03:00 PM. Reason: Mistakes
Reply With Quote
  #15  
Old 03-31-2004, 06:13 PM
Iceplug's Avatar
IceplugPlease Help New User Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Your Form5_Load actually has to be in your Form5 class .
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #16  
Old 03-31-2004, 06:55 PM
mycomputerman mycomputerman is offline
Freshman
 
Join Date: Mar 2004
Location: United States
Posts: 31
Default

Do you mean like this:

Public Class SoundClass
Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer
Public Const SND_SYNC = &H0
Public Const SND_ASYNC = &H1
Public Const SND_FILENAME = &H20000
Public Const SND_RESOURCE = &H40004
End Class
Public Class Form5
Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PlaySound(Application.StartupPath & "\final_answer.wav", 0, SND_FILENAME Or SND_ASYNC)
End Sub
End Class

If that is what you mean, Playsound, SND-FILENAME, and SND_ASYNC show up as errors being undefined.
Reply With Quote
  #17  
Old 04-01-2004, 06:39 AM
Iceplug's Avatar
IceplugPlease Help New User Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Don't you already have a form5 class? You need one in order to have a Form_Load event.
Do you even have a form in your project already?
Also, you need to instantiate a new soundclass in order to play a sound with that class.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #18  
Old 04-01-2004, 03:51 PM
mycomputerman mycomputerman is offline
Freshman
 
Join Date: Mar 2004
Location: United States
Posts: 31
Default

This is my Form5 code:

Public Class Form5

Windows Form Designer generated code
Upgrade Support

Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
(CODE)
End Sub

Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click
(CODE)
End Sub

Public Class SoundClass
Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer
Public Const SND_SYNC = &H0
Public Const SND_ASYNC = &H1
Public Const SND_FILENAME = &H20000
Public Const SND_RESOURCE = &H40004
Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PlaySound(Application.StartupPath & "\final_answer.wav", 0, SND_FILENAME Or SND_ASYNC)
End Sub
End Class
End Class

I am new with visualbasic.net and I am not sure on how to instantiate a new soundclass. Any help with it is well appreciated!!!!!!
Reply With Quote
  #19  
Old 04-01-2004, 04:00 PM
Iceplug's Avatar
IceplugPlease Help New User Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Well, first of all, your form5_Load subroutine needs to be moved into your Form5 class.
Second of all, you cannot declare a class inside of a class (the End Class must come before the Public Class, not after the other end class).
Third of all, to instantiate a new sound class, do something like this (follow my light blue comments):
Code:
Dim Sounds As SoundClass = New SoundClass
Dim xtra As Integer
'This is how you instantiate a new soundclass...
'to access a member of this class, type the variable name (not the class name)...
'in this case, Sounds
'and then a period.  Then select the member you want to access.
'It will look something like the following:
xtra = Sounds.SND_SYNC
Also, those constants in the sound class should have As Integer before the equals sign.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #20  
Old 04-01-2004, 07:46 PM
mycomputerman mycomputerman is offline
Freshman
 
Join Date: Mar 2004
Location: United States
Posts: 31
Default

Here is what I have:

Public Class Form5
(CODE)
Dim Sounds As SoundClass = New SoundClass
Dim xtra As Integer = Sounds.SND_FILENAME
Dim xtra1 As Integer = Sounds.SND_ASYNC
Dim Play As Integer = Sounds.PlaySound


Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
(CODE)
End Sub

Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click
(CODE)
End Sub

Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PlaySound(Application.StartupPath & "\final_answer.wav", 0, xtra Or xtra1)
End Sub
End Class

Public Class SoundClass
Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer
Public Const SND_SYNC As Integer = &H0
Public Const SND_ASYNC As Integer = &H1
Public Const SND_FILENAME As Integer = &H20000
Public Const SND_RESOURCE As Integer = &H40004
End Class

The only problem with the above code is with the orange part and the indigo part. The indigo part errors with Not Declared and the orange part errors with "Argument not specified for parameter 'flags' of 'Declare Auto Function PlaySound Lib "winmm.dll"(name As String, hmod As Integer, flags As Integer) As Integer'." Any ideas on this one? Thanks for all your help!!!!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Msgbox in user control? csuriv General 5 07-16-2003 09:06 PM
Passing User Defined Types to User Controls skiier General 1 07-01-2003 05:08 AM
track and store user logout time ziyun Web Programming 4 03-27-2002 12:16 AM
Appen user ishapiro Database and Reporting 0 09-21-2001 07:32 AM
case study problem dfdfsfer Database and Reporting 3 04-18-2001 07:02 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Please Help New User
Please Help New User
Please Help New User Please Help New User
Please Help New User
Please Help New User
Please Help New User Please Help New User Please Help New User Please Help New User Please Help New User Please Help New User Please Help New User
Please Help New User
Please Help New User
 
Please Help New User
Please Help New User
 
-->