Click here to Skip to main content
15,883,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to narrate a program describing how to play chess. My code for playing the sound file is [this is one of several sound files, with picture boxes showing the action]:
VB
My.Computer.Audio.Play(My.Resources.BoardSquares, AudioPlayMode.WaitToComplete)


But the program waits until all sound files are played before the screen refreshes to catch up with the narration. How can I refresh the screen before the next sound file is played?
Posted

1 solution

If you can use .NET Framework 3.5 or above (if you want to use Visual Studio, it should be VS 2008 or later; but Visual Studio is absolutely not required to build any project), you can do the following: reference assemblies PresentationCode and WindowsBase (part of WPF placed in GAC, so use ".NET" tag of "Add Reference" window).

VB
Dim audioFileName As String = '...

'... ...

Dim player As New System.Media.SoundPlayer(audioFileName)
player.Play()


Please see: http://msdn.microsoft.com/en-us/library/system.media.soundplayer.aspx[^].

It will play asynchronously (I tested it before posting the code, just in case).
Don't worry about WPF: your application does not have to be a WPF application, it can be anything.

One advice: try to use .NET API only, and nothing VB-specific.

—SA
 
Share this answer
 
v2
Comments
[no name] 18-Nov-12 21:08pm    
Thank you so much for your help. I will go and try your suggestions.
Sergey Alexandrovich Kryukov 18-Nov-12 21:59pm    
You are welcome. It will work, for sure.
Good luck, call again.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900