Wowza Community

Center CameraView inside the UIView

I wrote:

-(void*)getCameraView:(NSString*)param{
    
    __block UIView* result = nil;
    NSString* key = param;
    
    dispatch_sync(dispatch_get_main_queue(), ^{
        if (container == nil) {
            UIView *topView = [[[[UIApplication sharedApplication] keyWindow] subviews] lastObject];
            container = [[UIView alloc] initWithFrame:topView.bounds];
            [container setBackgroundColor:(UIColor.blackColor)];
        }
        
        if (self.goCoder == nil) {
            // Register the GoCoder SDK license key
            NSError *goCoderLicensingError = [WowzaGoCoder registerLicenseKey:key];
            if (goCoderLicensingError != nil) {
                // Log license key registration failure
                com_codename1_io_Log_p___java_lang_String(CN1_THREAD_GET_STATE_PASS_ARG fromNSString(CN1_THREAD_GET_STATE_PASS_ARG [goCoderLicensingError localizedDescription]));
            } else {
                // Initialize the GoCoder SDK
                self.goCoder = [WowzaGoCoder sharedInstance];
            }
        }
        
        
        if (self.goCoder != nil) {
            // Associate the U/I view with the SDK camera preview
            self.goCoder.cameraView = container;
            
            // Start the camera preview
            [self.goCoder.cameraPreview startPreview];
            
            result = container;
        }
        
    });
    return result;
}

Note that I used:

[container setBackgroundColor:(UIColor.blackColor)];

to see the size of the container (the default color is white).

Result (the camera preview IS NOT CENTERED inside its black UIView):

Moreover, when I rotate the screen from portrait to landscape, I get:

Could you help me to fix my code?

Note that for me it’s mandatory that I return a UIView with the camera preview (the reason is explained here:

https://stackoverflow.com/questions/58349108/from-ios-objective-c-code-and-android-java-code-to-a-codename-one-peercomponent

Thank you