Programming for MultiMedia:Sound 
Author Message
 Programming for MultiMedia:Sound

I hope I can get an answer here.

I am looking, in vain it seems, for any information on
how to program VB.NET to play sounds (.wav or any sound
files). Of course, there is BEEP, but I want to play a
chime, or some other sound to audibly signal an event. I
just don't see it. Yes, there is the PlaySound function,
but that appears to apply to C++ programming. Do I have
to design a C++ control to use?

Hope Not,
Richard Stauch
Long Beach, CA



Sat, 04 Jun 2005 09:35:13 GMT  
 Programming for MultiMedia:Sound
Amazingly, .NET has no built in direct support for multimedia of any kind.
I hear they are working on it for the next major release (After VS 2003)

For now, you have a few options:
 * You can use the Windows API.
    (This solution is the simplest from a deployment perspective)
    http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=463

 * You can use the old MCI32.OCX ActiveX control through COM Interop
    (This solution is the simplest from a development perspective)

 * You can use DirectX through COM Interop
    (best solution if you need to do any fancy multimedia stuff)
    http://msdn.microsoft.com/directx

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net


Quote:
> I hope I can get an answer here.

> I am looking, in vain it seems, for any information on
> how to program VB.NET to play sounds (.wav or any sound
> files). Of course, there is BEEP, but I want to play a
> chime, or some other sound to audibly signal an event. I
> just don't see it. Yes, there is the PlaySound function,
> but that appears to apply to C++ programming. Do I have
> to design a C++ control to use?

> Hope Not,
> Richard Stauch
> Long Beach, CA



Sat, 04 Jun 2005 10:17:26 GMT  
 Programming for MultiMedia:Sound
As Steve Orr said, you can use the MCI32 control, which is what I did. Seems
to work fine, and plays a variety of sound files (WAV, MP3). I use it for my
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
the next picture.

I was totally clueless when I first came across this control. On the chance
you or some other interested person is too, I've included my VB code below.

  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
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
"MCI.MMControl"
      'The best documentation that exists for this control seems to be at
website:
      '
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbco...
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)
      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
(optional).
      'If Wait=False, begin playing sound file and continue with execution.
      PlayerControl.Wait = False

      'If we can play the sound (should always happen), go ahead and play it
      If PlayerControl.CanPlay Then
         PlayerControl.Command = "Play" 'Play the sound (required)

         'If the picture display timer is on, increase the timer interval by
         'the length of the sound accompanying the picture so that we never
         'drop part of the narration describing the picture.
         If Not (PlayerControl Is Nothing) Then
            Timer1.Interval = Timer1.Interval + PlayerControl.Length
         End If
      Else
         MsgBox("Can't play sound file " & SoundFileName & ":" & vbCrLf _
         & "Error code = " & PlayerControl.Error.ToString & ", Error message
= " & PlayerControl.ErrorMessage)
      End If

   End Sub


Quote:
> I hope I can get an answer here.

> I am looking, in vain it seems, for any information on
> how to program VB.NET to play sounds (.wav or any sound
> files). Of course, there is BEEP, but I want to play a
> chime, or some other sound to audibly signal an event. I
> just don't see it. Yes, there is the PlaySound function,
> but that appears to apply to C++ programming. Do I have
> to design a C++ control to use?

> Hope Not,
> Richard Stauch
> Long Beach, CA



Sat, 04 Jun 2005 11:41:43 GMT  
 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



Sun, 05 Jun 2005 00:20:55 GMT  
 Programming for MultiMedia:Sound
Steve,

That is amazing, because they worked so hard to give us
data access, graphics, and all the rest, but sound seems
to have completely slipped their minds! I hope they add
it soon.

Thanks for all the information, though. I am still
checking everything out. Don Peters provided a more
practical solution, that is working for me (see my reply
to him). I hope MS can simply include such information in
the next edition of MSDN. That would be very helpful.

Thanks again,
Richard Stauch
Long Beach, CA

Quote:
>-----Original Message-----
>Amazingly, .NET has no built in direct support for

multimedia of any kind.
Quote:
>I hear they are working on it for the next major release
(After VS 2003)

>For now, you have a few options:
> * You can use the Windows API.
>    (This solution is the simplest from a deployment
perspective)
>    http://www.dotnetjunkies.com/tutorials.aspx?
tutorialid=463

> * You can use the old MCI32.OCX ActiveX control through
COM Interop
>    (This solution is the simplest from a development
perspective)

> * You can use DirectX through COM Interop
>    (best solution if you need to do any fancy
multimedia stuff)
>    http://msdn.microsoft.com/directx

>--
>I hope this helps,
>Steve C. Orr, MCSD
>http://Steve.Orr.net



Sun, 05 Jun 2005 00:30:13 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Sound, Wave, Multimedia, API, How?

2. Sound Without Multimedia

3. Multimedia MCI Control repeats the sound forever

4. MultiMedia Sound please help

5. Can MultiMedia control play AVI with sound track?

6. Multimedia Control Quality of Recorded Sound

7. linking multimedia sound bits in a MS-Access database to a VB-application

8. Multimedia Sound amplitude and frequency

9. Multimedia Sound amplitude and frequency

10. QBasic Sound Programs using Sound Blaster and Adlib Cards Here

11. Multimedia Programming with vb.NET

12. Easier directX/multimedia programming?

 

 
Powered by phpBB® Forum Software