Karel Petránek
05/19/2022, 11:36 PMAVCaptureVideoDataOutputSampleBufferDelegateProtocol
in Kotlin on iOS and the delegate method never gets called (equivalent code in Swift/ObjC works fine). I suspect it’s because of the protocol definition in Kotlin:
@kotlinx.cinterop.ExternalObjCClass public interface AVCaptureVideoDataOutputSampleBufferDelegateProtocol : platform.darwin.NSObjectProtocol {
@kotlinx.cinterop.ObjCMethod public open fun captureOutput(output: platform.AVFoundation.AVCaptureOutput, didOutputSampleBuffer: platform.CoreMedia.CMSampleBufferRef? /* = kotlinx.cinterop.CPointer<cnames.structs.opaqueCMSampleBuffer>? */, fromConnection: platform.AVFoundation.AVCaptureConnection): kotlin.Unit { /* compiled code */ }
@kotlinx.cinterop.ObjCMethod public open fun captureOutput(output: platform.AVFoundation.AVCaptureOutput, didDropSampleBuffer: platform.CoreMedia.CMSampleBufferRef? /* = kotlinx.cinterop.CPointer<cnames.structs.opaqueCMSampleBuffer>? */, fromConnection: platform.AVFoundation.AVCaptureConnection): kotlin.Unit { /* compiled code */ }
}
Note that both captureOutput
methods have the exact same signature, they only differ in parameter names. It is impossible to override both methods in Kotlin (it’s also impossible to define such interface in Kotlin code) so I suspect some trickery there. Has anyone met this issue before? Is there a workaround to make Kotlin properly override these ObjC methods?Karel Petránek
05/19/2022, 11:36 PMprivate class OutputListener: NSObject(), AVCaptureVideoDataOutputSampleBufferDelegateProtocol {
override fun captureOutput(
output: AVCaptureOutput,
didOutputSampleBuffer: CMSampleBufferRef?,
fromConnection: AVCaptureConnection
) {
println("captureOutput")
}
}
russhwolf
05/20/2022, 1:18 AMThomas
05/20/2022, 9:44 AM@Suppress("CONFLICTING_OVERLOADS")
to your delegate class.Thomas
05/20/2022, 9:47 AMThomas
05/20/2022, 9:47 AMKarel Petránek
05/20/2022, 10:41 AMKarel Petránek
05/20/2022, 10:42 AM