ok question simple. have 3 resources in visual basic project in visual studio, audio files. want application play sound name user typed in textbox.
to explain bit further: have resources "fire", "water" , "air". if user types air in textbox, use
my.computer.audio.play(my.resources.air, audioplaymode.background)
but don't want make copy of code each possibility, want make variable played object. can me? :s
you should put case statement
dim resourcefilepathprefix string if system.diagnostics.debugger.isattached() 'in debugging mode resourcefilepathprefix = system.io.path.getfullpath(application.startuppath & "\..\..\resources\") else 'in published mode resourcefilepathprefix = application.startuppath & "\resources\" end if 'you name files fire.wav, water.wav or whatever want. playerstream = resourcefilepathprefix & textbox1.text + ".wav" my.computer.audio.play(playerstream, audioplaymode.background)
or reference directly:
try my.computer.audio.play("c:\test\" & textbox1.text,audioplaymode.background) catch ex exception msgbox("the file not exist." & ex.message, msgboxstyle.critical) end try
assuming wav files @ c:\test :)
Comments
Post a Comment