Can you please share a code snippet of how you are calling startVideo() / stopVideo() on the Video Helper? Please ensure that you are calling either function on the main thread. Also, you would simply need to call those two functions and not subscribe/unsubscribe, except when the corresponding user joins and leaves.
Hello Richard, I am not calling subscribe/unsubscribe at toggle. However, the app was previously crashing when startVideo() was used on the main thread. To resolve this, we moved it to a background thread, as explained in the commented code. Please let me know if there is any quick fix I can apply.
func startVideo() {
if let videoHelper = ZoomVideoSDK.shareInstance()?.getVideoHelper() {
// Start local Userβs video.
/*
// -[AVCaptureSession startRunning] should be called from background thread. Calling it on the main thread can lead to UI unresponsiveness
// https://developer.apple.com/forums/thread/722309
*/
DispatchQueue.global(qos: .background).async { [weak self] in
guard let self = self else { return }
videoHelper.startVideo()
DispatchQueue.main.async {
videoHelper.rotateMyVideo(.portrait)
}
}
}
}
func stopVideo() {
if let videoHelper = ZoomVideoSDK.shareInstance()?.getVideoHelper() {
// Stop local User's video.
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
videoHelper.stopVideo()
}
}
}
Thank you for sending in your snippet, I will try to reproduce the issue locally with it. One thing I also want to mention is that start/stop video functionality involves sending this info the MMR so that other people would know your video is on/off. It takes time and cannot be called too frequently. So if someone is toggling the video on/off in quick succession, this might be expected behavior, especially if in an environment with an unstable connection.
Are you experiencing this issue even when someone toggles the video at, say, once every 5+ more seconds?
An additional thing- startVideo() returns an ZoomVideoSDKError object- you could try printing it out to determine what error code it returns when you receive a black screen.
Also, what kind of crash is occurring when you call startVideo() from the main thread? I must reiterate, you DO need to call start/stop video functions on the main thread. That is a requirement of our SDK.