Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4553446
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:56:52+00:00 2026-05-21T16:56:52+00:00

I am creating a WP7 application that requires various sound effects to be played

  • 0

I am creating a WP7 application that requires various sound effects to be played (on button press) over looped background music. The background music is initiated by pressing Button 1 and loops fine. When I press button3 (triggers a sound effect), the sound effect overlays on the background music fine on first press. However, when I press button3 again, the background music stops. I cannot figure out why this might be happening!? I have pasted the relevant portions of code below. Would appreciate any help.

public partial class MainPage : PhoneApplicationPage
{
    SoundEffect soundEffect;
    Stream soundfile;

    // Constructor
    public MainPage()
    {
        InitializeComponent();
    }



    static protected void LoopClip(SoundEffect soundEffect)
    {
        {
        SoundEffectInstance instance = soundEffect.CreateInstance();
        instance.IsLooped = true;
        FrameworkDispatcher.Update();
        instance.Play();
        }
    }

    public void PlaySound(string soundFile)
    {
        using (var stream = TitleContainer.OpenStream(soundFile))
        {

            var effect = SoundEffect.FromStream(stream);
            effect.Play();
        }
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        soundfile = TitleContainer.OpenStream("BackgroundMusic.wav");
        soundEffect = SoundEffect.FromStream(soundfile);  
        LoopClip(soundEffect);
    }


    private void button3_Click(object sender, RoutedEventArgs e)
    {
        PlaySound("sound3.wav");
    }

}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:56:53+00:00Added an answer on May 21, 2026 at 4:56 pm

    This should work if you are always working with Instances so change your code to this and it should clear up the problem:

    public partial class MainPage : PhoneApplicationPage
    {   
    
        SoundEffectInstance loopedSound = null;
    
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }
    
        static protected void LoopClip(SoundEffect soundEffect)
        {
            loopedSound = soundEffect.CreateInstance();
            loopedSound.IsLooped = true;
            loopedSound.Play();
        }
    
        public void PlaySound(string soundFile)
        {
            SoundEffect sound = SoundEffect.FromStream(Application.GetResourceStream(new Uri(soundFile, UriKind.Relative)).Stream);
            SoundEffectInstance instance = sound.CreateInstance();
            instance.Play();
        }
    
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            SoundEffect sound = SoundEffect.FromStream(Application.GetResourceStream(new Uri(@"BackgroundMusic.wav", UriKind.Relative)).Stream); 
            LoopClip(sound);
        }
    
    
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            PlaySound("sound3.wav");
        }
    
    }
    

    The above example assumes your sound files are set with Build Action = Content and are in the top level directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an application for WP7 where the background of it (a grid) receives
Creating a calculator-like dialog, I noticed that quickly clicking on a button in IE
I have built a WP7.1 application that uses a local database. I used sqlmetal
Right now I'm creating an application for WP7 and have recieved alot of feedback
Here is my problem: I am creating a WP7 application and need to list
I am on an initial stage of creating a Birthday reminder application in WP7
I'm creating a library application that will act as a wrapper for an exposed
I'm creating a WP7 app that needs to continue running when the user is
I'm creating MaskedTextBox in WP7.1 In that i want to set the Prompt char
I'm creating the MaskedTextBox in WP7.1 In that i want to select all text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.