What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » playing a .wav file in VB

playing a .wav file in VB
Author: Message:
.blade//
Veteran Member
*****

Avatar

Posts: 2856
Reputation: 39
35 / Male / –
Joined: Jan 2004
O.P. Huh?  playing a .wav file in VB
I can't remember anymore how to, but I know it's possible to play a .wav file in VB WITHOUT using the Windows Media component, anyone have a little code.


Also: anyone know a quick code to save a file name in a text document without using the Rich Text Document component?
[Image: A%20Pointy%20Rock.jpg]
06-18-2004 10:10 PM
Profile PM Web Find Quote Report
Hah
Full Member
***

Avatar
Im in a good mood - take advantage!

Posts: 224
37 / Male / –
Joined: May 2003
RE: playing a .wav file in VB
http://www.vbcodemagician.dk/tips/media_wavplay.htm

thats a very simple example of how to play a wav file in vb.

As for Also how to save a filename in a text document without rich edit control:

Have you tried:

code:
filechan = freefile
filename = "hello.txt"
Open filename for append as fileChan
    Print #filechan, "The text to be appended to end of file."
Close #filechan


Hope i understood what you meant there. If you could explain in more detail I'll definately be able to help you.

Hah
This post was brought to you by Hah!
(and he takes no responsibility for it :p)

[Image: signatures.jpg]

{Current Web Site}
06-18-2004 10:15 PM
Profile E-Mail PM Web Find Quote Report
.blade//
Veteran Member
*****

Avatar

Posts: 2856
Reputation: 39
35 / Male / –
Joined: Jan 2004
O.P. RE: playing a .wav file in VB
quote:
Originally posted by Hah
http://www.vbcodemagician.dk/tips/media_wavplay.htm

thats a very simple example of how to play a wav file in vb.

As for Also how to save a filename in a text document without rich edit control:

Have you tried:

code:
filechan = freefile
filename = "hello.txt"
Open filename for append as fileChan
    Print #filechan, "The text to be appended to end of file."
Close #filechan


Hope i understood what you meant there. If you could explain in more detail I'll definately be able to help you.

Hah

thanks, that's exactly what I needed, but I forgot to ask how to open that file again with out the RTD :P

edit: NVM, I am not going to be needing the open/close code anyways...

This post was edited on 06-18-2004 at 10:30 PM by .blade//.
[Image: A%20Pointy%20Rock.jpg]
06-18-2004 10:21 PM
Profile PM Web Find Quote Report
.blade//
Veteran Member
*****

Avatar

Posts: 2856
Reputation: 39
35 / Male / –
Joined: Jan 2004
O.P. RE: playing a .wav file in VB
Sorry for the double post, but is there a way to play the file without freezing the form?
[Image: A%20Pointy%20Rock.jpg]
06-18-2004 10:59 PM
Profile PM Web Find Quote Report
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
42 / Male / Flag
Joined: Jan 2003
RE: playing a .wav file in VB
quote:
Originally posted by Hah
http://www.vbcodemagician.dk/tips/media_wavplay.htm

thats a very simple example of how to play a wav file in vb.
That example uses the sndPlaySound API, that is obsolete. You should use the PlaySound one instead (that also lets you play a sound in background; ie. without freezing the form):

PlaySound function:
code:
Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Alternate Declare for when using a resource or memory location:
code:
Declare Function PlaySound_Res Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As Long, ByVal hModule As Long, ByVal dwFlags As Long) As Long
I personally prefer thise second declaration. If you can use the StrPtr function you should use this second one, imo

Platforms: Win 32s, Win 95/98, Win NT

PlaySound plays a waveform sound through the speakers. This sound could be a .wav file, a system event sound (such as the system startup sound), or a sound resource stored in an application. Note that when the function needs to play an application resource or a RAM-loaded sound, Visual Basic users must use the alternate declare of the function in order to pass the numeric identifier of the sound instead of a string. The function returns 0 if an error occured, or a non-zero value if successful.

  • lpszName
    The name or some other identifier of the sound. Its exact format depends on the flags passed as dwFlags.

  • hModule
    A handle to the application module containing the sound resource the play, if needed. If the function does not need this information, pass 0 for this parameter.

  • dwFlags
    Zero or more of the following flags specifying what lpszName refers to and how to play the sound:
    • SND_ALIAS = &H10000
      lpszName is a string identifying the name of the system event sound to play.
    • SND_ALIAS_ID = &H110000
      lpszName is a string identifying the name of the predefined sound identifier to play.
    • SND_APPLICATION = &H80
      lpszName is a string identifying the application-specific event association sound to play.
    • SND_ASYNC = &H1
      Play the sound asynchronously -- return immediately after beginning to play the sound and have it play in the background.
    • SND_FILENAME = &H20000
      lpszName is a string identifying the filename of the .wav file to play.
    • SND_LOOP = &H8
      Continue looping the sound until this function is called again ordering the looped playback to stop. SND_ASYNC must also be specified.
    • SND_MEMORY = &H4
      lpszName is a numeric pointer refering to the memory address of the image of the waveform sound loaded into RAM.
    • SND_NODEFAULT = &H2
      If the specified sound cannot be found, terminate the function with failure instead of playing the SystemDefault sound. If this flag is not specified, the SystemDefault sound will play if the specified sound cannot be located and the function will return with success.
    • SND_NOSTOP = &H10
      If a sound is already playing, do not prematurely stop that sound from playing and instead return with failure. If this flag is not specified, the playing sound will be terminated and the sound specified by the function will play instead.
    • SND_NOWAIT = &H2000
      If a sound is already playing, do not wait for the currently playing sound to stop and instead return with failure.
    • SND_PURGE = &H40
      Stop playback of any waveform sound. lpszName must be an empty string.
    • SND_RESOURCE = &H4004
      [ė]lpszName[/i] is the numeric resource identifier of the sound stored in an application. hModule must be specified as that application's module handle.
    • SND_SYNC = &H0
      Play the sound synchronously -- do not return until the sound has finished playing.

Example:

code:
' First play the SystemStart event sound synchronously.  Then loop
' playing the file C:\Sounds\scream.wav for 5 seconds before stopping.
Dim retval As Long  ' return value of the function

' Synchronously play the SystemStart sound.  This function returns when the sound is done.
retval = PlaySound("SystemStart", 0, SND_ALIAS Or SND_SYNC)

' Now loop the .wav file for five seconds before purging its playback.  Note that
' we don't want the default sound to play if the file is not found.
retval = PlaySound("C:\Sounds\scream.wav", 0, SND_FILENAME Or SND_ASYNC Or SND_NODEFAULT Or SND_LOOP)
Sleep 5000  ' wait for 5 seconds while sound loops
retval = PlaySound("", 0, SND_PURGE Or SND_NODEFAULT)  ' stop playback
Messenger Plus! en espaņol:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
06-18-2004 11:23 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On