Hack Forums
[.NET] How to Play a Sound in vb.net without having the sound file separately - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] How to Play a Sound in vb.net without having the sound file separately (/showthread.php?tid=4473281)



How to Play a Sound in vb.net without having the sound file separately - Vaxorr - Oct 3, 2014

hey,

i want to play a sound in background without having to provide the path i mean is there any way to like bind the sound with my Project so i can play the sound on any pc without having to provide the sound file separately.


Thanks,
Null


* - SIM-964740 - Oct 3, 2014

Import it to your resources. You can do this by going to: My project (Double Click) > Resources > Add Resource > File.

Call with: My.Resources.<Identifier>


* - SIM-1078643 - Oct 3, 2014

Either add it to resources or download it from an url.
Code
Dim webclient As New Net.WebClient

Dim sound() As Byte = webclient.DownloadData("http://www.wavsource.com/snds_2014-09-21_2643861498792963/sfx/applause_y.wav")
My.Computer.Audio.Play(sound, AudioPlayMode.Background)



* - Marwix - Oct 3, 2014

Pretty much like Selcouth just said; Import the soundtrack or mp3 to your resources and then write the code to play it.

http://dbzbt99.weebly.com/how-to-add-background-music-in-visual-basic.html

Hope it helps you!


* - Vaxorr - Oct 3, 2014

if i have imported it to the resources and called it, i will have to get the resources folder with my app in order for it to run ?


* - PatientZero - Oct 3, 2014

(Oct 3, 2014 06:56 AM)Null‎ Wrote:  if i have imported it to the resources and called it, i will have to get the resources folder with my app in order for it to run ?

I recommend streaming the sound from a URL if the client has internet connection.
It will make the download a lot smaller.


* - TheBarret - Oct 3, 2014

(Oct 3, 2014 09:00 AM)PatientZero Wrote:  I recommend streaming the sound from a URL if the client has internet connection.
It will make the download a lot smaller.

Again does not make sense, your speed still depends on server speed / ISP speed, plus the fact it might just happen the server response isn't what you hoped for andthus lagging your entire application since you do not use ASynch stream/download.

Where did you learn to program? sirously..who told you?


* - Vaxorr - Oct 3, 2014

My idea is the following.
An if statement to check for internet connection, if yes then download the file and play it if no then copy the sound file provided to a dir like temp, like what odus said. Thoughts ?


* - PatientZero - Oct 3, 2014

(Oct 3, 2014 09:28 AM)TheBarret Wrote:  Again does not make sense, your speed still depends on server speed / ISP speed, plus the fact it might just happen the server response isn't what you hoped for andthus lagging your entire application since you do not use ASynch stream/download.

Where did you learn to program? sirously..who told you?
Maybe then you can host it on your own web-server?
I taught myself and I know how to program thnx.


(Oct 3, 2014 10:42 AM)Null‎ Wrote:  My idea is the following.
An if statement to check for internet connection, if yes then download the file and play it if no then copy the sound file provided to a dir like temp, like what odus said. Thoughts ?

Sounds good if you can do it 🤝


* - +Haze - Oct 3, 2014

(Oct 3, 2014 10:42 AM)Null‎ Wrote:  My idea is the following.
An if statement to check for internet connection, if yes then download the file and play it if no then copy the sound file provided to a dir like temp, like what odus said. Thoughts ?

Reverse you're idea and it would be good.

Check the Temp folders, if the song is not their then download it using webclient and store it in the temp folder. Then play. That way you always download it once.
And use the async method too so your UI doesn't hang.


* - Cornflower Blue இڿڰۣ-ڰۣ— - Oct 3, 2014

(Oct 3, 2014 11:09 AM)+Haze Wrote:  Reverse you're idea and it would be good.

Check the Temp folders, if the song is not their then download it using webclient and store it in the temp folder. Then play. That way you always download it once.
And use the async method too so your UI doesn't hang.

"Reverse you're idea and it would be good." - I loled.


* - +Haze - Oct 3, 2014

(Oct 3, 2014 11:13 AM)Cornflower Blue இڿڰۣ-ڰۣ— Wrote:  "Reverse you're idea and it would be good." - I loled.

😏😏
*your and *there

my bad. Now jog on.


* - $lick - Oct 3, 2014

(Oct 3, 2014 11:13 AM)Cornflower Blue இڿڰۣ-ڰۣ— Wrote:  "Reverse you're idea and it would be good." - I loled.

"if the song is not their"

I loled while loling watching loli.


* - Cornflower Blue இڿڰۣ-ڰۣ— - Oct 3, 2014

(Oct 3, 2014 11:16 AM)๖ۣۜLazy™ Wrote:  "if the song is not their"

I loled while loling watching loli.

But it has to be their for it to play. Their going to have to downloaded the song for playing it.