I’m trying to implement `AVCaptureVideoDataOutputS...
# kotlin-native
k
I’m trying to implement
AVCaptureVideoDataOutputSampleBufferDelegateProtocol
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:
Copy code
@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?
Delegate code:
Copy code
private class OutputListener: NSObject(), AVCaptureVideoDataOutputSampleBufferDelegateProtocol {
    override fun captureOutput(
        output: AVCaptureOutput,
        didOutputSampleBuffer: CMSampleBufferRef?,
        fromConnection: AVCaptureConnection
    ) {
        println("captureOutput")
    }
}
r
You might be able to define both overrides by suppressing the duplicate method error
t
You need to add
@Suppress("CONFLICTING_OVERLOADS")
to your delegate class.
There is actually a complete sample how to use it in kotlin too.
k
Oh, that’s awesome, thank you! 🙏
Suppress seems to actually work 👍