shogo4405 / HaishinKit.swift

Camera and Microphone streaming library via RTMP and SRT for iOS, macOS, tvOS and visionOS.
BSD 3-Clause "New" or "Revised" License
2.78k stars 617 forks source link

MultiCam does not work in SwiftUI #1331

Closed Lyashenko-Alex closed 12 months ago

Lyashenko-Alex commented 1 year ago

Describe the bug

I have tested SwiftUI example. It works fine with single camera. When I try to use multicam for PIP mode, it shows black screen. If I add the below code, canvas is black. I cannot see nothing.

if #available(iOS 13.0, *) { let front = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front) rtmpStream.attachMultiCamera(front) }

Will you please help me to work multicam in SwiftUI?

To Reproduce

In the viewModel, in the registerForPublishEvent() function, add the below code.

if #available(iOS 13.0, *) { let front = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front) rtmpStream.attachMultiCamera(front) }

The view is black.

Expected behavior

It should show PIP view like iOS example with Storyboard.

Version

1.5.8

Smartphone info.

Additional context

No response

Screenshots

No response

Relevant log output

No response

Lyashenko-Alex commented 1 year ago

HaishinSwiftUITest.zip

Attached project source code.

shogo4405 commented 12 months ago

It seems that being called in the following order is not working:

MTHKSwiftUIView#updateUIView() ViewModel#registerForPublishEvent()

It worked well when attaching 'attachMultiCam' or 'attachCamera' in ViewModel's #config().