How to play MIDI and WAV from VB ???? 
Author Message
 How to play MIDI and WAV from VB ????

On Fri, 11 Sep 1998 01:47:27 +0800, "Eric, Chow Hoi Ka"

Quote:

>Hello,

>How can I use API to play MIDI and WAV files ????

>Would you please to give me a simple example ?????

>Best regards,
>Eric

>--

>     _  |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|  _
>    / ) |     Eric, Chow Hoi Ka            ICQ# : 3463514     | ( \
>   / /  |                                                     |  \ \

>(((\ \> |/ )                                               ( \| </ /)))
>(\\\\ \_/ /                                                 \ \_/ ////)
> \       /                                                   \        /
>  \    _/     http://www.*-*-*.com/ ~d951686/               \_     /
>  /   / |_____________________________________________________| \    \
> /   /                                                           \    \

This was posted a few days ago, I'll repost it here for ya.....

On Tue, 8 Sep 1998 08:05:27 -0400, "Black Knight"

Quote:

>-------------------------
>You can play Wav Files in Visual Basic by using the MCI functions. For
>playing sound, follow these steps:

>1. Start a new project. Add a Command Button (Command1)
>2. In the General Declarations Section of the form, place this code:

>    Private Declare Function sndPlaySound Lib "MMSystem" (ByVal lpSound As
>String, ByVal flag As Integer) As Integer

>    Global Const SND_ASYNC = &H1

NOTE: Global Const isn't allowed in a form...SC

Quote:

>    Private Sub PlaySoundButton_Click()
>        Dim Successful As Integer
>        Dim SoundName As String

>        SoundName = "The_Sound_You_Want_To_Play"
>        Successful = sndPlaySound(SoundName, SND_ASYNC)
>    End Sub
>-------------------------

I agree with this answer but would add the following to allow more
options on how the sound is played.  I am assuming the 32-bit version
of VB4.0

In  the declarations section of a module add:

'Same function Black Knight suggested
Public Declare Function sndPlaySound Lib "winmm.dll" Alias
"sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long)
As Long

'use this function to determine if the user has a sound device
configured
Public Declare Function waveOutGetNumDevs Lib "winmm" () As Long

'other constants to specify how the sound is to be played
Global Const SND_SYNC = &H0 'just after the sound is ended exit
function
Global Const SND_ASYNC = &H1 'just after the beginning of the sound
exit function
Global Const SND_NODEFAULT = &H2 'if the sound cannot be found no
error message
Global Const SND_LOOP = &H8 'repeat the sound until the function is
called again
Global Const SND_NOSTOP = &H10 'if currently a sound is played the
function will return without playing the selected sound
Global Const sndTYPE = SND_ASYNC Or SND_NODEFAULT 'sound is played
asynchronously and no error is generated if not found

Then the original code suggested becomes:

    Private Sub PlaySoundButton_Click()
        Dim Successful As Long
        Dim SoundName As String
        Dim i as long

        SoundName = "The_Sound_You_Want_To_Play"
        'only play sound if sound device exists
        i = waveOutGetNumDevs()
        If i > 0 Then 'There is at least one sound device.
             Successful = sndPlaySound(SoundName, sndTYPE)
        Else
            MsgBox "You have no sound device configured.", vbCritical
       End If

    End Sub

Hope this helps....

Scott Coker                          ICQ# 11107324
**************************************************
          |/_/ |/_/
           \__/
          ~|oo~
 |\,,,,.../  y
  \        /          <----## ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
  /...    |
  \\  `~~||
   \\    ||
    hh   mm          It's that time of year again!
**************************************************
The views and opinions expressed by me
do not reflect those of KBSI.



Mon, 26 Feb 2001 03:00:00 GMT  
 How to play MIDI and WAV from VB ????
Hello,

How can I use API to play MIDI and WAV files ????

Would you please to give me a simple example ?????

Best regards,
Eric

--

     _  |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|  _
    / ) |     Eric, Chow Hoi Ka            ICQ# : 3463514     | ( \
   / /  |                                                     |  \ \

(((\ \> |/ )                                               ( \| </ /)))
(\\\\ \_/ /                                                 \ \_/ ////)
 \       /                                                   \        /
  \    _/     http://www.sftw.umac.mo/~d951686/               \_     /
  /   / |_____________________________________________________| \    \
 /   /                                                           \    \



Tue, 27 Feb 2001 03:00:00 GMT  
 How to play MIDI and WAV from VB ????
You could use the MCI control...
Or you could use the sndPlaySound API for wav files, and the mciSendString
and mciGetErrorString APIs for MIDIs
                               John Maher


Quote:
>Hello,

>How can I use API to play MIDI and WAV files ????

>Would you please to give me a simple example ?????

>Best regards,
>Eric

>--

>     _  |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|  _
>    / ) |     Eric, Chow Hoi Ka            ICQ# : 3463514     | ( \
>   / /  |                                                     |  \ \

>(((\ \> |/ )                                               ( \| </ /)))
>(\\\\ \_/ /                                                 \ \_/ ////)
> \       /                                                   \        /
>  \    _/     http://www.sftw.umac.mo/~d951686/               \_     /
>  /   / |_____________________________________________________| \    \
> /   /                                                           \    \



Fri, 02 Mar 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to play MIDI and WAV from VB ????

2. Playing WAV and MIDI files in VB 4.0

3. Playing WAV files and MIDI files

4. HELP: Can't play MIDI and WAV at same time

5. Midi and Wav auto-play

6. Playing Large Wav and Midi without DoEvents

7. How To Play MIDI/WAV Sounds

8. Playing Large Wav and Midi without DoEvents

9. Play WAV and MIDI

10. MIDI playing and multiple MIDI's.

11. .WAV and MIDI files in VB

12. Playing MIDIs in VB programs

 

 
Powered by phpBB® Forum Software