I need to play a sound file (wav or mp3 in order) from a service in Windows 7/2008 ... just like we did in WinXP, it no longer works. I have completed this question Play a wave file from a Windows service (C #) without any success in various combinations. The sound plays perfectly through the debugger, but as soon as I install it as a service in which it does not play, and the event logs confirm that the call is being made. I also followed the link http://bresleveloper.blogspot.co.il/2012/06/c-service-play-sound-with-naudio.html with the same result.
The following is a snippet of code. This is a C # service since VS 2010, .NET 4.0, NAudio 1.5.4.0. I am using InstallUtil to install / uninstall a service.
WRT code, I comment on Wav or MP3 material and one of the methods every time ... they all reproduce sound well.
static class Program { [DllImport("kernel32.dll")] public static extern Boolean AllocConsole(); static void Main(string[] args) { m_eventLog = new EventLog(); m_eventLog.Source = "EventLoggerSource"; if(args.Length > 0 && args[0].ToLower() == "/console") { AllocConsole(); EventLoggerApp app = new EventLoggerApp(); app.Start(); m_eventLog.WriteEntry("INFO (Calling Player)"); string fileFullPath=@ "c:\aaasound\bunny_troubles.wav", fileFullPath2=@ "c:\aaasound\dreams.mp3";
source share