|
-
Oct 7th, 2006, 11:12 AM
#1
Thread Starter
Junior Member
Importing sound files
I'm trying to make a program that will play sounds. Is it possible to import the sounds into the program so I don't have to direct the program towards a file? So I can just write something like
Instead of:
VB Code:
Play sound(C:\Audio\Sounds\car.wav)
idk know if the "play" or "play sound" commands are real, I'm just using them for the sake of ease.
-
Oct 7th, 2006, 11:54 AM
#2
Re: Importing sound files
Coincidentally there is a PlaySound api function but you still must supply full path+file name:'
VB Code:
Private Const SND_APPLICATION = &H80 'look for application specific association
Private Const SND_ALIAS = &H10000 'name is a WIN.INI [sounds] entry
Private Const SND_ALIAS_ID = &H110000 'name is a WIN.INI [sounds] entry identifier
Private Const SND_ASYNC = &H1 'play asynchronously
Private Const SND_FILENAME = &H20000 'name is a file name
Private Const SND_LOOP = &H8 'loop the sound until next sndPlaySound
Private Const SND_MEMORY = &H4 'lpszSoundName points to a memory file
Private Const SND_NODEFAULT = &H2 'silence not default, if sound not found
Private Const SND_NOSTOP = &H10 'don't stop any currently playing sound
Private Const SND_NOWAIT = &H2000 'don't wait if the driver is busy
Private Const SND_PURGE = &H40 'purge non-static events for task
Private Const SND_RESOURCE = &H40004 'name is a resource name or atom
Private Const SND_SYNC = &H0 'play synchronously (default)
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Sub Form_Load()
PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_FILENAME Or SND_ASYNC
End Sub
-
Oct 7th, 2006, 12:24 PM
#3
Fanatic Member
Re: Importing sound files
You can try using the resource option in visual basic.
Go to Add-Ins>Add-In Manager.
Select "VB 6 Resource Editor"
Tick "Loaded/Unloaded"
Press OK
Press Tools>Resource Editor
And from the second button to the right at the top of the new window you see, then add your file.
After that, I think you have to use the LoadRes() or something. This part of the Resource Editor I'm not too sure of.
-
Oct 7th, 2006, 04:02 PM
#4
Re: Importing sound files
There's a link to a very good tutorial on resource files in my signature. To play the sounds from the res file:
VB Code:
Option Explicit
'Form level code.
'YOU MUST COMPILE TO AN EXECUTABLE TO MAKE IT WORK !!!
'-----------------------------------------------------
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As Long, ByVal hModule As Long, ByVal dwFlags As Long) As Long
'Required constants.
Const SND_ASYNC = &H1 'Play asynchronously.
Const SND_RESOURCE = &H40004 'Name is a resource name or atom.
Const SND_PURGE = &H40 'Release memory.
'Toggle playing by clicking on the form.
Dim OnOff As Boolean
Private Sub Form_Click()
'Alternate clicks on the form will start/stop playback.
Dim RetVal As Long
If OnOff = True Then
OnOff = False
'Reference nothing and purge memory.
RetVal = PlaySound(0, App.hInstance, SND_PURGE)
ElseIf OnOff = False Then
OnOff = True
'Reference the res file (101)
RetVal = PlaySound(101, App.hInstance, SND_RESOURCE Or SND_ASYNC)
End If
Caption = OnOff
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|