CSCore not working in a windows service

199 Views Asked by At

I have a program that uses the CSCore library to detect applications which are playing audio and makes some info about them retrievable via web service.

It worked create as a console application but I wanted to have it run as a windows service. I changed it over to a windows service and only moved a few lines that called some initialization and shutdown function.

Not that I have done this the AudioSessionManager2.GetSessionEnumerator().Count is always 1. The only session it is returning is a process with ID 0. (Note: My working console version of the program always returns process 0, along with all other processes which play audio).

My VolumeManager class is the exact same as the console application version but it isn't working. I am don't know how I can debug it more. I checked for null objects and made sure everything is being called.

public List<AudioSessionControl2> GetSessions()
{
    List<AudioSessionControl2> sessions = new List<AudioSessionControl2>();

    if (sessionManager != null)
    {
        Log("Session Count: " + sessionManager.GetSessionEnumerator().Count);  //THIS IS AWAYS 1
    }

    foreach (var session in sessionManager.GetSessionEnumerator())
    {
        AudioSessionControl2 session2 = session.QueryInterface<AudioSessionControl2>();
        Log("Session2 Process: " + session2.Process.Id); //AWAYS 0

        if (session2 != null && session2.Process != null && session2.Process.MainWindowTitle != null && session2.Process.MainWindowTitle != "")
        {
            Log("Added session"); //NOT CALLED BECAUSE THE PROCESS WITH ID 0 HAS NO TITLE
            sessions.Add(session2);
        }
    }

    return sessions;
}

Why isn't this working as a service?

Thanks


Edit: I have posted this as an issueon the projects GitHub repo. Hopefully @thefiloe will be able to assist me in solving this problem.

0

There are 0 best solutions below