Invalid LiveSource stream resolution in standalone application

I need to get a camera stream resolution from JPEGLiveSource in standalone application (using MIPSDK 2017 R2):

static void GetResLive(Guid streamid)
{
    var jpegLive = new JPEGLiveSource(_camera);
    jpegLive.StreamId = streamid;
    jpegLive.LiveModeStart = true;
    jpegLive.Height = 0;
    jpegLive.Width = 0;
    jpegLive.Init();
    jpegLive.LiveContentEvent += jpegLiveContentEventHandler;
 
    // ... wait for key press here
    
    jpegLive.LiveContentEvent -= jpegLiveContentEventHandler;
    jpegLive.Close();
}

jpegLiveContentEventHandler() method just prints LiveContent resolution.

But if I call GetResLive() for the first time with id of any stream (but not default) I get the resolution of default stream. But if I call this method for the second time with same (or another) stream id, the resolution will be correct.

Am I doing something wrong?

Thanks.

This is probably because you have not initialized the “Media” environment.

When this is NOT done, the initial call will perform a automatic initialization - but can in that case loose some parameters.

Insert this statement at start of your code:

VideoOS.Platform.SDK.Media.Environment.Initialize();

Thank you for your help. The issue was solved.