audio problem

  • Thread starter Thread starter andrews
  • Start date Start date
A

andrews

I have a problem with audio

private sub playing(Byval somefilename as string)
My.Computer.Audio.Play(My.Resources.somefilename,AudioPlayMode.Background)
end sub


private sub choose
if good then
playing("wav1.wav")
else
playing("wav2.wav")
end sub

wav1.wav and wav2.wav are audio files that I put in resources
and good is a boolean variable
but in my.comp..... somefilename is not accepted and gives a error
Is there a solution?
Thanks for any response
 
andrews said:
I have a problem with audio

private sub playing(Byval somefilename as string)
My.Computer.Audio.Play(My.Resources.somefilename,AudioPlayMode.Background)
end sub

private sub choose
if good then
playing("wav1.wav")
else
playing("wav2.wav")
end sub

wav1.wav and wav2.wav are audio files that I put in resources
and good is a boolean variable
but in my.comp..... somefilename is not accepted and gives a error
Is there a solution?
Thanks for any response

Instead of using My.Crap, use the direct way to System.Media.SoundPlayer
You can pass a Stream to it's constructor. Use Assembly.GetManifestresourceStream
to open the stream.
 
andrews said:
I have a problem with audio

private sub playing(Byval somefilename as string)
My.Computer.Audio.Play(My.Resources.somefilename,AudioPlayMode.Background)
end sub


private sub choose
if good then
playing("wav1.wav")
else
playing("wav2.wav")
end sub

wav1.wav and wav2.wav are audio files that I put in resources
and good is a boolean variable
but in my.comp..... somefilename is not accepted and gives a error
Is there a solution?
Thanks for any response
.

That's because those are resources and not files, which is what the Play
method expects. This artical shows how to use resources for what you want to
do.

http://blogs.vbcity.com/xtab/archive/2006/02/03/5813.aspx

Mike
 
Back
Top