Audio.Play relative path?

darrenbooy

Member
Joined
Mar 16, 2009
Messages
8
Programming Experience
Beginner
Hi,

I need to play a sound file: Sounds\open_creaky_door.wav"

However the code only works if I specify the EXACT location:

My.Computer.Audio.Play("c:\sounds\open_creaky_door.wav")

Is there a way I can set the relative path to something like this?

My.Computer.Audio.Play("\sounds\open_creaky_door.wav")

cheers
 
The path relative to what?

You probably want to do a little preprocessing on the path using some functions in IO.Path
 
I have my program saved into a directory and I want to load a sound file from a sub directory called 'sounds'.

Surely its something much more straight forward than that I remember there was something curdir???? Although that was a long time ago (possibly with VB6).
 
Try this...

Dim sounddir As String = IO.Path.Combine(Application.StartupPath,"sounds")
Dim soundpath as String = IO.Path.Combine(sounddir,"open_creaky_door.wav")


Then pass soundpath in.


If you want to do it all in one, you can do IO.Path.Combine(Application.StartupPath,"sounds\open_creaky_door.wav")
- I just thought it may be sensible to keep the directory path separately.
 
Back
Top