|
-
Feb 6th, 2007, 10:26 PM
#1
Thread Starter
Junior Member
Random sounds/Embedding project files into self-containing exe
I know how to play a single sound, but I need code that will play any unset number of sounds at random intervals, and at random times. Also, I need to know how to embed these sounds and other project files into a self-containing exe program so I only have to distribute the exe file and not the external sounds, etc. Thanks.
-
Feb 6th, 2007, 11:55 PM
#2
Member
Re: Random sounds/Embedding project files into self-containing exe
if you add alot of sound files.
your exe could be upto 500 mb big?
you sure you want 2 do that
my questions will be in vb6 or visual studios 2005 
-
Feb 7th, 2007, 12:30 AM
#3
Re: Random sounds/Embedding project files into self-containing exe
To embed sound files into your executable you'll need to store them in a resource file which is compiled with your application. Search these forums for resource and you should find many examples.
Here's a link to a pretty good tutorial....
http://www.thevbzone.com/l_res.htm
Once you've got that part of it working, then you can concentrate on the random selection bit.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Feb 7th, 2007, 01:34 AM
#4
Re: Random sounds/Embedding project files into self-containing exe
One exe file without an installation in VB... Not something you really want to do...
-
Feb 7th, 2007, 03:49 PM
#5
Thread Starter
Junior Member
Re: Random sounds/Embedding project files into self-containing exe
OK got that to work, thanks. Now how do I randomly play sounds at different intervals or at certain times? Thanks.
-
Feb 7th, 2007, 07:22 PM
#6
Re: Random sounds/Embedding project files into self-containing exe
Try something like this...
Start a new project, put a timer on the form and set its Enabled property to False and paste the following code onto the form. This code assumes your resource file contains 6 wavs with ids numbered from 1 to 6.
VB Code:
Option Explicit
Private Const SND_MEMORY = &H4
Private Const SND_NODEFAULT = &H2
Private Const SND_SYNC = &H0
Private Declare Function PlaySound Lib "WINMM.DLL" Alias "PlaySoundA" ( _
ByRef Sound As Any, _
ByVal hLib As Long, _
ByVal lngFlag As Long) As Long
Private Const MinInterval As Long = 100 ' Minimum interval between sounds
Private Const MaxInterval As Long = 10000 ' Maximum interval between sounds
Private Const NumWavResources As Long = 6 ' Set to the number of wavs in the resource file
Private Sub PlayRandomSound()
'
' This assumes the wav resource ids are numbered from 1 to NumWavResources
'
Dim DataArray() As Byte
DataArray = LoadResData(Int(Rnd * NumWavResources) + 1, "WAVE")
Call PlaySound(DataArray(0), 0, SND_MEMORY Or SND_NODEFAULT Or SND_SYNC)
Erase DataArray
End Sub
Private Sub Form_Load()
'
' Seed the random number generator
'
Randomize
'
' Set the timer's initial interval to a random number
' between MinInterval and MaxInterval.
' The timer is initially disabled at design time
'
Timer1.Interval = CLng(Rnd * MaxInterval) + MinInterval + 1
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
'
' Play a random sound when the timer fires
'
PlayRandomSound
'
' Change the timer's interval
'
Timer1.Enabled = False
Timer1.Interval = CLng(Rnd * MaxInterval) + MinInterval + 1
Timer1.Enabled = True
End Sub
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Feb 10th, 2007, 04:49 PM
#7
Thread Starter
Junior Member
Re: Random sounds/Embedding project files into self-containing exe
Thanks guys so much! If you want to see why I needed this program, go download it at http://www.kelceycoe.com/software/Kelcey Coe.zip.
WARNING: Not for anyone under 18!
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
|