Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How to play sound in winforms. I am using below code but its not play.

C#
Stream audioStream = new MemoryStream(Properties.Resources.TestSound.ReadByte());
            SoundPlayer player = new SoundPlayer(audioStream);
            player.Play();
Posted

Check this, http://msdn.microsoft.com/en-us/library/4y171b18.aspx[^] & http://msdn.microsoft.com/en-us/library/ms143770.aspx[^]

The Stream passed to the stream parameter should be a Stream containing a .wav file. The data returned by the Read method of the Stream should be the data within a .wav file.
 
Share this answer
 
v2
Comments
divesh12 10-Feb-12 16:02pm    
Please Update my code if possible.
If you want to play 2 videos at the same time you need to enter 3 parts of code:

Part 1:

C#
using System.Runtime.InteropServices; //with this code you are able to import dll files


Part 2:

under:
C#
public Form1()
        {
            InitializeComponent();
        }



enter code:
C#
[DllImport("winmm.dll")]
        private static extern long mciSendString(
            string command,
            StringBuilder returnValue,
            int returnLength,
            IntPtr winHandle);//imports a dll file and creates a new command



Part 3:

C#
string filename1 = "";//location of first file
mciSendString("close mf1", null, 0, IntPtr.Zero);
mciSendString("open \"" + filename1 + "\" type mpegvideo alias mf1", null, 0, IntPtr.Zero);
mciSendString("play mf1", null, 0, IntPtr.Zero)



this worked for me;if you want to know more about this code search for MCI(Media Control Interface);Some extra commands:
pause mf1
resume mf1
stop mf1
seek mf1 to x // x is some number
try them to see what they do
 
Share this answer
 
Comments
divesh12 13-Feb-12 8:00am    
No video, Just Audio Sound file like on Click, on save, On Update, On Delete.
I used below code. Put sound file in Resources.
C#
SoundPlayer player = new SoundPlayer(Properties.Resources.sound1);
                    player.Play();

sound1 is media file name for example.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900