943,106 Members | Top Members by Rank

View Poll Results: This is help-ful for you ?
Yes 10 100.00%
No 0 0%
Voters: 10. You may not vote on this poll

Ad:
  • C# Code Snippet
  • Views: 3928
  • C# RSS
3

Add sound file into Resource and access it. in .net (C#)

by on Feb 6th, 2010
1. Right click on your project name in solution explorer.
2. Point the cursor on Add then choose Existing Item...
3. Now go to the Location of your sound file and select that sound file.
4. Now select your sound file in solution explorer then Right click on it choose Properties and change its Build Action property(Content to Embedded Resource)
5.Build the program or one time Debug the program.
6. Now if you want to play sound file when a particular Form is loaded then use the given code in Form_Load event.
NOTE:-In this code Dreamer.wav is name of sound file.
ASHISH
Attached Thumbnails
Click image for larger version

Name:	Step_1_2.JPG
Views:	1337
Size:	35.4 KB
ID:	13530  
C# Code Snippet (Toggle Plain Text)
  1. using System.Reflection;
  2. using System.IO;
  3. using System.Resources;
  4. using System.Media;
  5. using System.Diagnostics;
  6.  
  7.  
  8. namespace Yournamespace
  9. {
  10. public partial class Form2 : Form
  11. {
  12. public Form2()
  13. {
  14. InitializeComponent();
  15. }
  16.  
  17. private void Form2_Load(object sender, EventArgs e)
  18. {
  19.  
  20. Assembly assembly;
  21. Stream soundStream;
  22. SoundPlayer sp;
  23. assembly = Assembly.GetExecutingAssembly();
  24. sp = new SoundPlayer(assembly.GetManifestResourceStream("Yournamespace.Dreamer.wav"));
  25. sp.Play();
  26.  
  27. }
  28.  
  29. }
  30. }
Comments on this Code Snippet
Feb 7th, 2010
0

Re: Add sound file into Resource and access it. in .net (C#)

It doesn't works ...

I have:
C# Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. using System.Reflection;
  11. using System.IO;
  12. using System.Resources;
  13. using System.Media;
  14. using System.Diagnostics;
  15.  
  16. namespace Browser
  17. {
  18. public partial class Form1 : Form
  19. {
  20. public Form1()
  21. {
  22. InitializeComponent();
  23. }
  24. private void Form1_Load(object sender, EventArgs e)
  25. {
  26. Assembly assembly;
  27. Stream soundStream;
  28. SoundPlayer sp;
  29. assembly = Assembly.GetExecutingAssembly();
  30. sp = new SoundPlayer(assembly.GetManifestResourceStream("Browser.Billie_Jean.mp3"));
  31. sp.Play();
  32. }
  33. // etc.

When i debug my program , no sound sounds ... maybe because it's MP3 ?
Last edited by charqus; Feb 7th, 2010 at 3:24 pm.
Junior Poster in Training
charqus is offline Offline
64 posts
since Feb 2010
Feb 7th, 2010
0

Re: Add sound file into Resource and access it. in .net (C#)

I can't edit my post
--------------------------
Look at this: http://files.uploadffs.com/d/a/f2b0a5b2/code.PNG
I press F5 , and my sound doesn't sing !!!
Junior Poster in Training
charqus is offline Offline
64 posts
since Feb 2010
Feb 11th, 2010
0

Re: Add sound file into Resource and access it. in .net (C#)

Hi........
you are using different way to add sound file into Resources.
but in article i m using different way to add sound file into Resources.
plz use given step to sound file.
and also try different different sound file.
Actually, There are 2 - 3 way to add file into resources.

Tell me it is working or not?
Last edited by ashishkumar008; Feb 11th, 2010 at 7:51 am.
Light Poster
ashishkumar008 is offline Offline
45 posts
since Nov 2009
Nov 22nd, 2010
0

Re: Add sound file into Resource and access it. in .net (C#)

please tell me some other way for this problem.
Newbie Poster
Shlesh is offline Offline
6 posts
since Nov 2010
Message:
Previous Thread in C# Forum Timeline: Change Title bar Font
Next Thread in C# Forum Timeline: Jagged Array





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC