Quantcast
Viewing all articles
Browse latest Browse all 12583

VB audio playback: puzzling behaviour

VB, VS 2012, Windows Form

I have timer that, once the main timer has been stopped, triggers a secondary half-second timer to make a button flash between an on and off colour.  When the colour is "on", a beep sounds, i.e. every second, until the stop button is clicked.

Until I got around to making it more flexible, this has been hard-coded in as:
My.Computer.Audio.Play(My.Resources.sndWindows_Error, AudioPlayMode.Background)

This has worked fine up to now but only if hard-coded in the Play() function.  If I use a global with the resource assigned to it it beeps once and once only.  Try...Catch reveals a "Wave header is corrupt" exception:
Dim sndTimeUp = My.Resources.sndWindows_Error
My.Computer.Audio.Play(sndTimeUp, AudioPlayMode.Background)

In both cases the audio defaults to a System.IO.UnmanagedMemoryStream but forcing to a System.IO.Stream - which Play() is expecting - doesn't make any difference.

Why does the assignation make the difference?

Thanks for any help,
Duncan


Viewing all articles
Browse latest Browse all 12583

Trending Articles