Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I am use for play sound ;
C#
string soundPath = "G:\\altYapiTest\\altYapiTest\\Resources\\ses2.wav";

but I want use this
C#
string(etc.) soundPath = Properties.Resources.ses2



I added to the Resources.

What I have tried:

C#
string soundPath = "G:\\altYapiTest\\altYapiTest\\Resources\\ses2.wav";


EDIT

namespace altYapiTest
C#
using System.Media;


C#
SoundPlayer sesCal = new SoundPlayer();
string sesYolu;
sesYolu = "G:\\altYapiTest\\altYapiTest\\Resources\\ses2.wav";
sesCal.SoundLocation = sesYolu;
sesCal.Play();
Posted
Updated 16-Nov-16 8:56am
v2
Comments
Richard Deeming 16-Nov-16 13:39pm    
In order to answer your question, we need to know what you're using to play the file.

Click "Improve question" and add the full namespace and name of the control you're using.

1 solution

To load the file from an embedded resource, you're going to need to use the SoundPlayer.Stream[^] property instead of the SoundLocation property.
C#
SoundPlayer sesCal = new SoundPlayer();
sesCal.Stream = Properties.Resources.ResourceManager.GetStream("ses2.wav");
sesCal.Play();

NB: The SoundPlayer.Play[^] method returns immediately, and plays the sound on a background thread. If you want your code to wait until the sound has finished playing, which will block the UI, you would need to use the SoundPlayer.PlaySync[^] method.
 
Share this answer
 
Comments
Member 12833990 17-Nov-16 12:19pm    
Thank you :)

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