Results 1 to 4 of 4

Thread: Playing sound

  1. #1

    Thread Starter
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242
    Does anyone know where I can find a tutorial on how to play *.wav files?
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  2. #2
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    that's easy search this forum for the topic!
    What do you want? just the sndplay api or something like direct sound to mix more than one wavefile?
    Sanity is a full time job

    Puh das war harter Stoff!

  3. #3
    Banned
    Join Date
    Dec 2000
    Location
    USA, NJ
    Posts
    72

    Smile code

    ok two ways to do this. one is to goto components and
    instert the mmcontrol "microsoft mutlimedia control 6.0."
    where ever you want to play a sound put this code.
    code:
    cdsave.ShowOpen 'You dont have to put this in it just is to 'open a wav file
    MMControl1.FileName = cdsave.FileName 'or put in ex '"c:\wav.wav" your file name
    'stops mmcontrol
    MMControl1.Command = "Stop"
    'opens file
    MMControl1.Command = "Open"
    'plays file
    MMControl1.Command = "Play"

    thats one way and it can play most sound files but ive only used wav and mp3's.

    if you want to do it threw api put this code in, but its hard
    code:

    Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
    Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
    Private TheFileName As String, RecordMode As Boolean, dwreturn(1 To 4) As Long
    Private ret As String * 128, OpenFile As Boolean, playingfile As Boolean

    Dim tmp As String * 255
    Dim lenShort As Long
    Dim ShortPathAndFie As String
    mciSendString "close mpeg", 0&, 0&, 0&
    'check for an existing playing song
    If playingfile = True Then mciSendString "stop mpeg", 0&, 0&, 0&

    'close any open files first, to use this the mcierror function should not be used
    If OpenFile = True Then mciSendString "close mpeg", 0&, 0&, 0&

    'I have included a common Dialog box so you can choose an mp3
    Open1.FileName = "" 'remove any previous filenames
    Open1.flags = cdlOFNExplorer 'explorer interface
    Open1.Filter = "Supported Files|*.mp3;*.wav" 'allow wav's or mp3's
    Open1.ShowOpen
    FileName = Open1.FileName
    If FileName = "" Then Exit Sub 'If the user clicks cancel then nothing to open

    lenShort = GetShortPathName(FileName, tmp, 255)
    ShortPathAndFie = Left$(tmp, lenShort)
    dwreturn(1) = mciSendString("open " & ShortPathAndFie & " type MPEGVideo Alias mpeg", 0&, 0&, 0&)

    If dwreturn(1) <> 0 Then 'not success
    MCIError (dwreturn(1))
    Exit Sub
    End If
    OpenFile = True
    cmdPlay_Click

    Dim dwreturn(1 To 2) As Long
    Dim ret As String * 128
    'is the record mode turned on
    If RecordMode = True Then 'yes
    dwreturn(1) = mciSendString("open new type waveaudio Alias tune", 0&, 0&, 0&)
    dwreturn(2) = mciSendString("record tune", 0&, 0, 0) 'play the mp3 after this one
    For i = 1 To 2
    If dwreturn(i) <> 0 Then
    MCIError dwreturn(i)
    Exit Sub
    End If
    Next i
    End If
    'Now play the open mp3 or wav
    dwreturn(1) = mciSendString("play mpeg from 0", 0&, 0&, 0&)

    If dwreturn(1) <> 0 Then
    MCIError dwreturn(1)
    Exit Sub
    End If

    note: i didnt do all this code i have talked to some one who helped me.

    ull probly have to fix that a little too.
    if ur a newbie i would use the first one cause api is hard. and u can make it invisable and tell it to do all the cmds. you can figer it out easly.

    o yea put this in your code in the exit sub.
    mmcontrol1
    MMControl.Command = "Close"
    api
    mciSendString "close mpeg", 0&, 0&, 0&

  4. #4

    Thread Starter
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242
    Sorry i havent been able to check the forum lately but I'll take a look at the control and check out the api code. thanks.
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width