Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 2nd, 2003, 06:00 PM
Authorized User
 
Join Date: Jun 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default Playing a WAV without interupting sub

Hi all,

I have a routine that plays a wav. I call this routine from other routines. The problem that I have is that the calling sub ends up pausing while the wav is played before it completes. I am an amateur programmer. I was wondering if there is a way (separate thread?) to call the routine that plays the wav but have it NOT interupt the rest of my routine?

Thanks in advance.

Raymond Deux
 
Old July 3rd, 2003, 10:53 AM
Authorized User
 
Join Date: Jul 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When using the win32API to play a wav from VB NET you need to first declare the following...

 '//Win32API
    '//Both integer args and return were originally Longs - .NET Integer = vb6 Long
    Declare Function PlaySound Lib "winmm.dll" _
    Alias "PlaySoundA" (ByVal lpszName As String, _
                        ByVal hModule As Integer, _
                        ByVal dwFlags As Integer) As Integer

Then you can make a sub....


Friend Sub PlayAudio(ByVal FileName As String)
        '//call win32api function to play audio (wav) file alert
        Dim retval As Integer
        retval = PlaySound(FileName, 0, 1)
        'last param is SND_SYNC as integer
        'value set to 0 plays sound Synchronously (waits until sound ends before playing next)
        'value set to 1 plays sound Asynchronously (does not wait to play next sound)
    End Sub

in the comments above you'll see that the last param determines if sound waits or or doesn't. If you want you can modify the sub above to take that as a param as well. This is a snippet from an app I wrote for work. This should solve your problem, just use value of 1 to make app not wait for sound to finish. Threads shouldn't be necessary.

hope this helps
Tek


 
Old July 3rd, 2003, 01:28 PM
Authorized User
 
Join Date: Jun 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Tek,

Thank you. That did the trick. I had a declaration and sub similar to yours and I was running it in ASYNC mode. I guess somewhere, it did not work as I expected. Your code works great. Thanks again.

Ray
 
Old July 4th, 2003, 08:00 PM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwincusi
Default

i am a beginner in vb.net can you share me the code of your routine that plays the wav, thank you

HEY_HEY
 
Old July 4th, 2003, 10:55 PM
Authorized User
 
Join Date: Jun 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The code is in this thread a few posts above.
 
Old July 5th, 2003, 10:24 AM
Authorized User
 
Join Date: Jul 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

shadowpug,

No problem ! :) Glad to help

aldwincusi: as shadow said the code is a few posts up in this thread, just copy it.

peace
Tek





Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent,Plz help...Problem with playing wav msg Andisheh C# 2005 0 July 5th, 2007 04:43 AM
How to playing music in C#? Viet Hoang C# 2005 4 June 13th, 2006 03:51 AM
playing with textbox ninjai ASP.NET 1.0 and 1.1 Basics 1 September 24th, 2005 12:38 PM
Playing music in C# Fightfish C# 0 June 26th, 2005 08:09 AM
playing embedded video sentme_mail Flash (all versions) 0 November 14th, 2004 11:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.