By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,989 Members | 2,392 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,989 IT Pros & Developers. It's quick & easy.

Play wavs in VB2005.

P: n/a
Hi.

I'm struggle with playing a wav in Visual Basic. First I wanted to use
My.Computer.Audio.Play() method but I realized it's not working if I want to
have music in background.

I found in internet SoundPlayer Class but unfortunately I can't find it in
my Visual Studio Application. Whenever I try to use it

Dim Player New SoundPlayer ...

VS 2005 doesn't find it.

What's wrong ? Please help me. Thnaks

Regards.
--
ZikO
GG 5557876
Nov 12 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
If you search for SoundPlayer in the Object Browser (View / ObjectBrowser),
you'll find that it lives in the System.Media.Soundplayer namespace.

The ObjectBrowser is handy for figuring out what you need references to.

Robin S.

"ZikO" <ze***@op.plwrote in message news:ej**********@news.onet.pl...
Hi.

I'm struggle with playing a wav in Visual Basic. First I wanted to use
My.Computer.Audio.Play() method but I realized it's not working if I want
to
have music in background.

I found in internet SoundPlayer Class but unfortunately I can't find it in
my Visual Studio Application. Whenever I try to use it

Dim Player New SoundPlayer ...

VS 2005 doesn't find it.

What's wrong ? Please help me. Thnaks

Regards.
--
ZikO
GG 5557876

Nov 12 '06 #2

P: n/a
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:68******************************@comcast.com. ..
If you search for SoundPlayer in the Object Browser (View /
ObjectBrowser), you'll find that it lives in the
System.Media.Soundplayer namespace. The ObjectBrowser is handy for
figuring out what you need references to. Robin S.
"ZikO" <ze***@op.plwrote in message news:ej**********@news.onet.pl...
What would be the reason I don't see it in Object Browser? I can't See
System.Media.SoundPlayer, I can't even see System.Media ?!

Was it something wrong during instalation?

Regards.
--
ZikO
GG 5557876
Nov 12 '06 #3

P: n/a
"ZikO" <ze***@op.plschrieb:
What would be the reason I don't see it in Object Browser? I can't See
System.Media.SoundPlayer, I can't even see System.Media ?!

Was it something wrong during instalation?
Maybe your project is lacking references to the library containing the
class. Look up the DLL name in the documentation on the 'SoundPlayer' class
and add a reference via "Project" -"Add reference...".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 12 '06 #4

P: n/a
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:ef**************@TK2MSFTNGP03.phx.gbl...
"ZikO" <ze***@op.plschrieb:
>What would be the reason I don't see it in Object Browser? I can't See
System.Media.SoundPlayer, I can't even see System.Media ?!
Was it something wrong during instalation?
Maybe your project is lacking references to the library containing the
class. Look up the DLL name in the documentation on the 'SoundPlayer'
class and add a reference via "Project" -"Add reference...".
I found it in Add reference ... window, I've added as System reference but
it still can't recognize that it exist, I still can't use it. This is a very
new area for me and probably Im doing something wrong. Can someone explain
it to me by step by step, please? Thanks so much.
--
ZikO
GG 5557876
Nov 12 '06 #5

P: n/a
Try adding

Imports System.Media.Soundplayer

to the top of your class, before the Class definition.

Or go back to the References for your project (double-click
on My Project in Solution Explorer and choose the References
tab). In the bottom of the window, you see "Imported namespaces".
Find System.Media.Soundplay and check the checkbox.
(You have to click on it twice; there's a bug in VS2005).
This will import it into your entire project.

Robin S
-----------------
"ZikO" <ze***@op.plwrote in message news:ej**********@news.onet.pl...
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:ef**************@TK2MSFTNGP03.phx.gbl...
>"ZikO" <ze***@op.plschrieb:
>>What would be the reason I don't see it in Object Browser? I can't See
System.Media.SoundPlayer, I can't even see System.Media ?!
Was it something wrong during instalation?
Maybe your project is lacking references to the library containing the
class. Look up the DLL name in the documentation on the 'SoundPlayer'
class and add a reference via "Project" -"Add reference...".

I found it in Add reference ... window, I've added as System reference but
it still can't recognize that it exist, I still can't use it. This is a
very new area for me and probably Im doing something wrong. Can someone
explain it to me by step by step, please? Thanks so much.
--
ZikO
GG 5557876

Nov 14 '06 #6

P: n/a
Try adding
Imports System.Media.Soundplayer
to the top of your class, before the Class definition.
Or go back to the References for your project (double-click
on My Project in Solution Explorer and choose the References
tab). In the bottom of the window, you see "Imported namespaces".
Find System.Media.Soundplay and check the checkbox.
(You have to click on it twice; there's a bug in VS2005).
This will import it into your entire project.
Robin S
-----------------
In Imported namespaces I can see only System.Media, I can't see
SoundPlay!Maybe it's because System.Media are namespaces whilst SoundPlay is
a class. Anyway, even when I import System.Media by double-click I can't see
difference. The tick has appeared besides System.Media but in code window,
editor still can't see SoundPlay class. It's really odd.
--
ZikO
GG 5557876
Nov 15 '06 #7

P: n/a
You're right, it's the System.Media namespace.

If you type in Dim Player as System.Media.Soundplayer
does the Intellisense kick in after Media. and show
Soundplayer?

Open the object browser (View / ObjectBrowser).
Search for "soundplayer". Do you see it?

Here's a link to an article on msdn about how to use it;
this has an example in VB. Is there something about how
you're using it that is incorrect?

http://msdn2.microsoft.com/en-us/lib...undplayer.aspx

What did you mean about not being able to use
My.Computer.Audio.Play() because it doesn't play music
in the background? Do you mean you want to have it playing
while you're doing other stuff, and if you click off of the
program, it stops playing?

Robin S.
---------------------------------------

"ZikO" <ze***@op.plwrote in message news:ej**********@news.onet.pl...
>Try adding
Imports System.Media.Soundplayer
to the top of your class, before the Class definition.
Or go back to the References for your project (double-click
on My Project in Solution Explorer and choose the References
tab). In the bottom of the window, you see "Imported namespaces".
Find System.Media.Soundplay and check the checkbox.
(You have to click on it twice; there's a bug in VS2005).
This will import it into your entire project.
Robin S
-----------------

In Imported namespaces I can see only System.Media, I can't see
SoundPlay!Maybe it's because System.Media are namespaces whilst SoundPlay
is a class. Anyway, even when I import System.Media by double-click I
can't see difference. The tick has appeared besides System.Media but in
code window, editor still can't see SoundPlay class. It's really odd.
--
ZikO
GG 5557876

Nov 16 '06 #8

P: n/a
I found it in Video Tutorials about VB.NET 2005 SoundPlayer class
http://msdn.microsoft.com/vstudio/ex...dioPart1CS.wvx

There was one missing line:

' Friend WithEvents MyPlayer As New System.Media.SoundPlayer

(of course I could use Imports System.Media ...) After this I could work
with SoundPlayer class e.g.

' myPlayer.SoundLocation = "/..."
' myPlayer.Play()

Without this line SoundPlayer couldn't be recognized by VB.
Open the object browser (View / ObjectBrowser).
Search for "soundplayer". Do you see it?
Yes.
Here's a link to an article on msdn about how to use it;
this has an example in VB. Is there something about how
you're using it that is incorrect?
http://msdn2.microsoft.com/en-us/lib...undplayer.aspx
I just couldn't use it anyhow because VB didn't recognized it but now it
works but that line above is not clear for me :/. Anyway it works now.
What did you mean about not being able to use
My.Computer.Audio.Play() because it doesn't play music
I mean that I want to play a few sounds at the same time, say song in the
background and some short sounds during clicking e.g. When I used
My.Computer.Audio.Play() and I use sound for clicking, the song stops
playing, as sound for clicking is supposed to play. Anyway SoundPlayer work
very similarly. I think I need to use Windows Media Player, although I
wanted to avoid that.

Thanks so much for giving me a hand :). I have done it with your help :).
Regards.
--
ZikO
GG 5557876
Nov 16 '06 #9

P: n/a
You're welcome. Good luck.

Robin S.
---------------------------------------
"ZikO" <ze***@op.plwrote in message news:ej**********@news.onet.pl...
>I found it in Video Tutorials about VB.NET 2005 SoundPlayer class
http://msdn.microsoft.com/vstudio/ex...dioPart1CS.wvx

There was one missing line:

' Friend WithEvents MyPlayer As New System.Media.SoundPlayer

(of course I could use Imports System.Media ...) After this I could work
with SoundPlayer class e.g.

' myPlayer.SoundLocation = "/..."
' myPlayer.Play()

Without this line SoundPlayer couldn't be recognized by VB.
>Open the object browser (View / ObjectBrowser).
Search for "soundplayer". Do you see it?

Yes.
>Here's a link to an article on msdn about how to use it;
this has an example in VB. Is there something about how
you're using it that is incorrect?
http://msdn2.microsoft.com/en-us/lib...undplayer.aspx

I just couldn't use it anyhow because VB didn't recognized it but now it
works but that line above is not clear for me :/. Anyway it works now.
>What did you mean about not being able to use
My.Computer.Audio.Play() because it doesn't play music

I mean that I want to play a few sounds at the same time, say song in the
background and some short sounds during clicking e.g. When I used
My.Computer.Audio.Play() and I use sound for clicking, the song stops
playing, as sound for clicking is supposed to play. Anyway SoundPlayer
work very similarly. I think I need to use Windows Media Player, although
I wanted to avoid that.

Thanks so much for giving me a hand :). I have done it with your help :).
Regards.
--
ZikO
GG 5557876

Nov 17 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.