Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Looping wav files with VB6 MM control

291 views
Skip to first unread message

Ed

unread,
Jun 9, 2004, 2:12:25 AM6/9/04
to
Hi,

Is there any way to achieve seamless looping wav files between the "From"
and "To" properties using VB6's MM Control?

I've been using the Notify event as the cue to start playing again, but this
causes a hole in the audio.

Help!!!!

Many thanks,

Ed.


MikeD

unread,
Jun 9, 2004, 8:14:41 AM6/9/04
to

"Ed" <e...@ANTISPAMtobysoft.com> wrote in message
news:ca69ob$hjo$1...@news6.svr.pol.co.uk...

> Hi,
>
> Is there any way to achieve seamless looping wav files between the "From"
> and "To" properties using VB6's MM Control?
>
> I've been using the Notify event as the cue to start playing again, but
this
> causes a hole in the audio.
>

Don't use the MM control for this. Instead, call Windows' PlaySound API
function. Here's an example. Add two command buttons to a form. Command1
starts playing the sound. Command2 stops it.


-----BEGIN CODE

Option Explicit

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal
lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
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_NODEFAULT = &H2 'silence not default, if sound not
found

Private Sub Command1_Click()

Dim sWavFileName As String
Dim lFlags As Long

'Hard-coded for example purposes only.
sWavFileName = "H:\WINNT\Media\ding.wav"
lFlags = SND_ASYNC Or SND_FILENAME Or SND_LOOP Or SND_NODEFAULT
PlaySound sWavFileName, 0&, lFlags

End Sub

Private Sub Command2_Click()

PlaySound vbNullString, 0&, SND_ASYNC

End Sub

----END CODE

This is much easier and more efficient than using the control.

Mike


Ed

unread,
Jun 9, 2004, 8:00:55 PM6/9/04
to
Thanks for that Mike. Can PlaySound be used to specify a portion within a
wav file to loop? i.e. Using an equivalent to MM Control's "From" and "To"
properties.

Thanks,

Ed.

"MikeD" <nob...@nowhere.edu> wrote in message
news:ueWfoshT...@TK2MSFTNGP10.phx.gbl...

MikeD

unread,
Jun 9, 2004, 9:40:53 PM6/9/04
to

"Ed" <e...@ANTISPAMtobysoft.com> wrote in message
news:ca88br$b0i$1...@newsg4.svr.pol.co.uk...

> Thanks for that Mike. Can PlaySound be used to specify a portion within a
> wav file to loop? i.e. Using an equivalent to MM Control's "From" and "To"
> properties.

No. PlaySound (or sndPlaySound for that matter) can only play a .wav file
from start to finish (although playback can be stopped at anytime by calling
the function again IF the sound was played asynchronously [meaning the
function returns immediately after playback has started]). To specify
"from" and "to" points, you'd need to use MCI (not necessarily the MM
control as you can use MCI API functions) or DirectX.

PlaySound is the easiest way to play a .wav sound, but it doesn't give you
much control. It allows you to loop the sound, play it synchronously
(meaning the function doesn't return until playback has finished) or
asynchronously, but not much else.

Mike


Ed

unread,
Jun 10, 2004, 7:56:23 AM6/10/04
to
Thanks again Mike. Time to delve into the murky world of MM API functions I
think.

Ed.

"MikeD" <nob...@nowhere.edu> wrote in message

news:u5zYHvoT...@TK2MSFTNGP10.phx.gbl...

Norm Cook

unread,
Jun 12, 2004, 9:52:04 AM6/12/04
to
Not that hard either:
http://www.geocities.com/smigman.geo/mci/wav.html

"Ed" <e...@ANTISPAMtobysoft.com> wrote in message news:ca9i99$99m$1...@newsg4.svr.pol.co.uk...

Ed

unread,
Jun 13, 2004, 12:59:14 PM6/13/04
to
Thanks Norm, but there's no mention of looping. There's a "repeat" command
for the MM API, but that appears to only apply to AVI files.

"Norm Cook" <norm...@cableone.net> wrote in message
news:10cm2io...@corp.supernews.com...

MikeD

unread,
Jun 13, 2004, 9:39:50 PM6/13/04
to

"Ed" <e...@ANTISPAMtobysoft.com> wrote in message
news:cai155$gq8$1...@news8.svr.pol.co.uk...

> Thanks Norm, but there's no mention of looping. There's a "repeat" command
> for the MM API, but that appears to only apply to AVI files.


MCI provides no "built-in" way to loop (like PlaySound does for a .wav
file). Even using the API, you'd have to do pretty much the same thing as
you've done with the MM control...only it's more involved because you need
to use a callback function to get notifications from MCI about playback
status (and thus determine when playback has stopped).

I have no idea if it'll help, but you might want to look into using DirectX.
I also don't know exactly what it is you're trying to do (apparently, loop
segments of .wav files, but that's just a guess). DirectX may help. I'm
not real familiar with DirectX so I can't say for sure. But you're
apparently not happy with what MCI or the PlaySound function can do, so you
may as well look into what DirectX offers.

Mike


0 new messages