Chris
Chris

Reputation: 3076

Visual Studio Windows Phone 7 play sound

I'm creating a Windows Phone 7 App and am trying to play a sound.

I have the code to do it but it cannot find the file when I try to run it on the emulator.

I have added the sound file as a resource (I think)

here is the code in case it is the problem

PlaySound(@"Sounds\show.wav");

And the function

private void PlaySound(string path)
    {
        try
        {
            if (!string.IsNullOrEmpty(path))
            {
                using (var stream = TitleContainer.OpenStream(path))
                {
                    if (stream != null)
                    {
                        var effect = SoundEffect.FromStream(stream);
                        FrameworkDispatcher.Update();
                        effect.Play();
                    }
                }
            }
        }catch(Exception e){
            timerCount.Text = path;
        }
    }

Upvotes: 3

Views: 3560

Answers (1)

Matt Lacey
Matt Lacey

Reputation: 65564

Set the Build Action on the file to Content.

Upvotes: 6

Related Questions