Asked by:
Silverlight 5 + XNA: Issue with SoundEffectInstance.Play() (or Resume() ) when Machine is locked

Question
-
Hi,
I am working on a Silverlight 5 business application, which will be running OOB occasionally. it has hardware interaction and thus at times a device externally can trigger a sound in application. well that's what is intended anyway.
for sound playback, I am using AUDIO namespace from XNA framework. all works well and XNA can play sound when machine is unlocked, however occasionally I noticed that when user locks his machine, sound won't play. it is irregular, and I haven't been able to identify any pattern.
to recreate this, I created a simple Silverlight application with 3 buttons on it, code as follows. Start_Button_click and Stop_Button_Click will play and stop audio respectively. Delayed_Button_Click will delay the method invocation for just enough time for me to lock machine.
private void Start_Button_Click(object sender, RoutedEventArgs e)
{
soundInstance.IsLooped = true;
soundInstance.Resume();
}
private void Stop_Button_Click(object sender, RoutedEventArgs e)
{
soundInstance.Stop(true);
}
private void Delayed_Button_Click(object sender, RoutedEventArgs e)
{
System.Threading.Thread.Sleep(5 * 1000);
soundInstance.IsLooped = true;
soundInstance.Resume();
}as I mentioned, Delayed_Button_Click always plays sound when machine is unlocked, but behaves irregular when machine is locked, it sometimes play, sometimes won't, when it fails exception is always as below:
Message=Value does not fall within the expected range.
StackTrace:
at Microsoft.Xna.Framework.Audio.XcpImports.CheckHResult(UInt32 hr)
at Microsoft.Xna.Framework.Audio.XcpImports.SoundEffectInstance_Play(SoundEffectInstance soundEffectInstance)
at Microsoft.Xna.Framework.Audio.SoundEffectInstance.Play()
InnerException:(well I tried with Play/resume as well, you call it, behaviour is same)
So after a lot of effort analysing code from different ways, I ended up every time with following code being the culprit.
[DllImport("agcore", EntryPoint = "SoundEffectInstance_Pause", CallingConvention = CallingConvention.Cdecl)] private static extern uint SoundEffectInstance_PauseNative(IntPtr pNativeSoundEffectInstance);
this is what is causing exception when method is invoked with windows locked but randomly. works superb when windows is unlocked.
If anyone out there has experienced this issue, please share your insight, else if any lady or gentlemen who could point to what is going on here and how can I resolve this issue.
least if someone has insights to AGCORE.dll and what this method is expecting which is not available.
Inputs are welcome.
Kind Regards,
SourabhMonday, September 16, 2013 12:44 PM
All replies
-
One potential workaround is to use a MediaElement instead of XNA to play the sound.Tuesday, September 24, 2013 1:33 AM
-
I wish I could use that, but I need to be able to play multiple media files simultaneously if need be. Thanks for response.
Regards,
Sourabh
Wednesday, September 25, 2013 11:31 AM -
Hi,
We have looked into the issue and from a support perspective this is really beyond what we can do here in the forums. If you cannot determine your answer here or on your own, consider opening a support case with us. Visit this link to see the various support options that are available to better meet your needs: http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone.
Thanks!
Shaleen Thapa
Monday, October 7, 2013 9:08 PM