473,387 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Play wavs in VB2005.

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
9 3569
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
"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
"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
"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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bill Dandreta | last post by:
I posted a message ("Help with my 1st Tkinter program") a few days ago complaining that Python did not have any built in basic cross platform sound capability. I was wrong (at least partly). Python...
2
by: Diego_Atos | last post by:
I've a problem. I've made a simple card game. Using winmm.dll i can simply play one file. However if i try to play 2 files at same time, the second stops the first one, due to the driver busy. ...
2
by: Jerry Spence1 | last post by:
1. Is there a more suitable, dedicated newsfeed for VB2005 yet? 2. I'm confused as to which version to get. I work for a small company and we will just need VB2005 on my PC. Therefore that tends...
0
by: Rich | last post by:
Hello, I just upgraded a vb2003 app to vb2005. The vb2003 app had/has a statusbar object - which contains panels and I can see the properties of the statusbar in the properties window in...
3
by: Jared | last post by:
I'm using the first code sample below to play WAV files stored as embedded resources. For some reason I *occasionally* get scratching and crackling. I'm using a couple WAVs that ship with...
1
by: erickwan88 | last post by:
I am doing a final year project for my school and is going to provide for an organization, so I am asking for some help on here. Indeed, I have no idea on how to get the input from my pen driver...
15
by: Aalaan | last post by:
I am presently a user of classic vb6 and hang out on those newsgroups. Some of you may be aware that there is a very anti MS and vb2005 feeling there. I have tried to get them to tell me which...
10
ADezii
by: ADezii | last post by:
Most Access Users fail to realize that they can significantly enhance their applications by introducing various sounds (*.WAVs) in response to specific events. The only intrinsic sound that Access...
1
by: Vae07 | last post by:
Ok so here is a brief summary of my problem. I need a pop up form that submits input text box information to a pocket excel workbook upon a command botton click. Text box inputs are checked for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.