Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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.

C#
[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.

Further to above, i do get this entry in output window:

A first chance exception of type 'System.ArgumentException' occurred in Microsoft.Xna.Framework.dll


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,
Sourabh
Posted
Updated 8-Oct-13 21:12pm
v2

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