Results 1 to 6 of 6

Thread: I cant get visual Basic to play a wav file??

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    54
    Hey i'm new here. I've tried everything from asking my boss if he knew Visual basic to my teacher who teaches visual basic and so far i have come up with nothing. I'm writing this program for a friend and trying to learn more about the concept of programming and I want to basically click on an option box and have it play a wav file. But the first problem i have is that visual basic doesnt seem to like to read files outside of the A drive.. or thats what my teacher seemed to explain to us. He couldnt get it working by using the hard drive or any other drive for that matter.. just the "A" drive.. which isnt user friendly when your actually trying to make a program for useful purposes.<br>
    the microsoft website gives me a line of coding with something to the effect of sndplaysnd but i'm confused as to what context that gets up in.. and i still cant point it to locate the wav file on the drive.<br>
    I saw a few ideas on encrypting the wav file into a file on visual basic or something like that. But again no sucess when implementing the suggested way of proceeding.<br>
    If anyone has any ideas or suggestions please feel free to try and help.. thanks alot..<br>

    ~Jason

  2. #2
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Smile play a wav

    This seems to work for me. just change the directory to a valid wav file.
    Place this in a command button

    Private Sub Command2_Click()
    x = ("C:\windows\media\logoff.wav")
    retval = sndPlaySound(x, SND_SYNC)
    End Sub

    in a module
    Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Public Const SND_SYNC = &H0 ' play synchronously (default)
    Matt

  3. #3
    Guest
    As Megatron would say:

    Keep in mind that sndPlaySound is superseded by PlaySound, hence it's obsolete.
    Code:
    Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    
    Private Sub Command1_Click()
    
        'Play the WAV
        PlaySound "C:\MyFile.wav", 0&, &H1
    
    End Sub

  4. #4
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    sorry the explaination....
    This uses the API. Everything in the module I got from the API test viewer that comes with vb.Then I called the function, plugging in the values. X being the directory, uflags telling it to play it synchronously.
    Matt

  5. #5
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    PlaySound has a wider range of, well, gadgets.

    See here for more info.

    PS: That teacher of yours requires some <ahem> rigorous retraining.

    [Edited by V(ery) Basic on 08-13-2000 at 01:27 PM]
    Courgettes.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    However, PlaySound (I think) loads the whole file into memory, then plays it. So, check out the StreamFrom sample in the Platform SDK, which used DirectSound to stream a wave file from disk.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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