
Programming for MultiMedia:Sound
Don,
Thank you very much. That is working for me, now. Just a
couple of extra notes:
First, I added the multimedia tool to the Windows Forms
Toolbox:
- Right-click the toolbox header
- Select Customize Toolbox
- Scroll down to Microsoft Multimedia Control, version 6.0
- Select the checkbox
- Hit OK
That adds a new tool called MMControl. Double-click that,
and two new References are added to the Solution Explorer
window: AxMCI and MCI. I think "stdole" was also added,
but I can't be sure. After that, I was able to add the
code you provided (repro below).
Then, I had a couple of minor problems. I had to install
the license keys from the MSDN (Pro) VS.NET DVD
(Extras\VB6Controls):
- Run RegEdit
- Select File|Import
- Browse to the .REG file on the CD or DVD
- Click OK, then File|Exit.
Last, I got an error that .WAV files could not be
automagically played. I had to add a line to the code to
set the device type, like so:
PlayerControl.DeviceType = "WaveAudio"
Of course, I also had to DIM the variables. After all
that, it was just a matter of deciding what .WAV file to
play!
This is great. Thanks again,
Richard Stauch
Long Beach, CA
Quote:
>-----Original Message-----
>As Steve Orr said, you can use the MCI32 control, which
is what I did. Seems
Quote:
>to work fine, and plays a variety of sound files (WAV,
MP3). I use it for my
Quote:
>picture slide show program. One nice feature is that you
can stop the
>playing of a sound under program control when the user
forces an advance to
Quote:
>the next picture.
>I was totally clueless when I first came across this
control. On the chance
Quote:
>you or some other interested person is too, I've
included my VB code below.
Quote:
> Public Sub PlaySoundFile(ByVal SoundFileName As String)
> 'Play the sound file having the filename of
SoundFileName
> 'Before using this code, you must add this .NET
multimedia control as
Quote:
>a reference, as follows:
> ' Go to the Solution Explorer
> ' Right click on "References" (or click on menu
item Project)
> ' Select list item "Add Reference..."
> ' Select tab "COM"
> ' Select Component Name "Microsoft Multimedia
Control 6.0 (SP3)",
>which is in MCI32.OCX
> ' Click button "Select", then button "OK"
> 'That object will then be added as a reference,
having the object name
Quote:
>"MCI.MMControl"
> 'The best documentation that exists for this
control seems to be at
Quote:
>website:
> '
>http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/vbcon98/htm
Quote:
>l/vbconusingmultimediamcicontrol.asp
> 'Note that PlayerControl.Length returns the length
of the sound in
>milliseconds.
> 'If the player control is already set up as an
object, close it
> If Not (PlayerControl Is Nothing) Then
> PlayerControl.Command = "Close" 'Immediately
closes the sound
>file (Must close in order to play it again)
> End If
> 'Create an instance of the multimedia object
(PlayerControl is Public)
Quote:
> PlayerControl = New MCI.MMControl()
> PlayerControl.FileName = SoundFileName 'Tell it
which sound file to
>play
> PlayerControl.Notify = True 'Don't notify us
when the sound is
>done playing (optional)
> PlayerControl.Command = "Open" 'Open the sound
file for playing
>(required)
> 'If Wait=True, wait until done playing before
continuing execution
Quote:
>(optional).
> 'If Wait=False, begin playing sound file and
continue with execution.
Quote:
> PlayerControl.Wait = False
> 'If we can play the sound (should always happen),
go ahead and play it
Quote:
> If PlayerControl.CanPlay Then
> PlayerControl.Command = "Play" 'Play the sound
(required)
> 'If the picture display timer is on, increase
the timer interval by
Quote:
> 'the length of the sound accompanying the
picture so that we never
Quote:
> 'drop part of the narration describing the
picture.
> If Not (PlayerControl Is Nothing) Then
> Timer1.Interval = Timer1.Interval +
PlayerControl.Length
Quote:
> End If
> Else
> MsgBox("Can't play sound file " & SoundFileName
& ":" & vbCrLf _
> & "Error code = " &
PlayerControl.Error.ToString & ", Error message
Quote:
>= " & PlayerControl.ErrorMessage)
> End If
> End Sub