title: Sound Effect Class in background agent
body: <p>I want to be able to play an audio file (a sound basically) from the background agent. I am using the following two approaches :</p>
  
  <p>1)</p>
  
  <pre><code>    SoundEffectInstance ClockTickInstance;
          StreamResourceInfo ClockTickStream;
          SoundEffect ClockTickSound;
          try {
          ClockTickStream = Application.GetResourceStream(new Uri(
            @"AudioFiles/NewHighScore.wav", UriKind.Relative));
                  ClockTickSound = SoundEffect.FromStream(ClockTickStream.Stream);
                  ClockTickInstance = ClockTickSound.CreateInstance();
                  ClockTickInstance.IsLooped = true;
                  ClockTickInstance.Volume = 1.0f;
                  ClockTickInstance.Pitch = 1.0f;
                  ClockTickInstance.Play();
                  ClockTickInstance.Stop();
  }
  </code></pre>
  
  <p>OR </p>
  
  <p>2)</p>
  
  <pre><code>var localFolder = Package.Current.InstalledLocation;
  Stream fileStream = await localFolder.OpenStreamForReadAsync("NewHighScore.wav");
  
  byte[] buffer = new byte[fileStream.Length];
  fileStream.Read(buffer, 0, System.Convert.ToInt32(fileStream.Length));
  fileStream.Close();
  SoundEffect soundefct = new SoundEffect(buffer, 16000, AudioChannels.Mono);
  FrameworkDispatcher.Update();
  soundefct.Play();
  </code></pre>
  
  <p>When i run the code from the xaml.cs file (i.e. from the foreground app) evrything works fine and the sound is played.</p>
  
  <p>But from the background agent, the code runs but no sound is heard. </p>
  
  <p>What could be the problem? </p>
  
  <p>the following article shows the list of APIs that can be used while the app is running in the background -
  <a href="http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662941(v=vs.105).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662941(v=vs.105).aspx</a></p>