Platforms to show: All Mac Windows Linux Cross-Platform
/AVFoundation/iOS Live QRCode Detect/iOS Live QRCode Detect
Required plugins for this example: MBS MacBase Plugin, MBS AVFoundation Plugin, MBS MacCG Plugin, MBS MacCF Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /AVFoundation/iOS Live QRCode Detect/iOS Live QRCode Detect
This example is the version from Wed, 11th May 2021.
Project "iOS Live QRCode Detect.xojo_binary_project"
Class App Inherits MobileApplication
EventHandler Sub Activated()
End EventHandler
EventHandler Sub Closing()
End EventHandler
EventHandler Sub Opening()
// Add your plugin license:
#Pragma Warning "No Plugin license is set"
// Setup AVFoundation
AVFoundation = New MyAVFoundationMBS
End EventHandler
Property AVFoundation As MyAVFoundationMBS
End Class
Class MainScreen Inherits MobileScreen
Control outputCanvas Inherits MobileCanvas
ControlInstance outputCanvas Inherits MobileCanvas
Constraint Constraint 1
Constraint Constraint 2
Constraint Constraint 3
Constraint Constraint 4
End Control
EventHandler Sub Closing()
If Self.CaptureSession <> Nil Then
Self.CaptureSession.stopRunning
Self.CaptureSession = Nil
End If
End EventHandler
EventHandler Sub Opening()
// We delay this since the AutoLayout has to be done before the camera session is activated.
Timer.CallLater 100, AddressOf Configure
End EventHandler
Sub Configure()
Self.CaptureSession = New AVCaptureSessionMBS
Var videoCaptureDevice As AVCaptureDeviceMBS = AVCaptureDeviceMBS.defaultDeviceWithMediaType(AVFoundationMBS.AVMediaTypeVideo)
If videoCaptureDevice = Nil Then
MessageBox "Failed to load video capute device"
Return
End If
Var error As NSErrorMBS
Var videoInput As New AVCaptureDeviceInputMBS(videoCaptureDevice, error)
If error <> Nil Then
MessageBox "VideoInput had an error: "+error.LocalizedDescription
Return
End If
If Self.CaptureSession.canAddInput(videoInput) Then
Self.CaptureSession.addInput(videoInput)
Else
MessageBox "Failed to add capture session input"
Return
End If
Var metadataOutput As New AVCaptureMetadataOutputMBS
If self.CaptureSession.canAddOutput(metadataOutput) Then
Self.CaptureSession.addOutput(metadataOutput)
Var availableTypes() As String = metadataOutput.availableMetadataObjectTypes
Var wantedTypes() As String
System.DebugLog "Available Types: " + String.FromArray(availableTypes, ", ")
If availableTypes.IndexOf(AVMetadataObjectMBS.AVMetadataObjectTypeQRCode) > -1 Then
wantedTypes.Add(AVMetadataObjectMBS.AVMetadataObjectTypeQRCode)
End If
metadataOutput.SetMetadataObjectTypes wantedTypes
Else
MessageBox "Failed to add capture session output. Simulator has no camera!"
Return
End If
Self.canvasLayer = CALayerMBS.layerFromHandle(outputCanvas.Handle)
Self.canvasLayer.BackgroundColor = CGColorMBS.Black
Self.previewLayer = New AVCaptureVideoPreviewLayerMBS(Self.CaptureSession)
Self.previewLayer.frame = Self.canvasLayer.bounds
Self.previewLayer.videoGravity = AVFoundationMBS.AVLayerVideoGravityResizeAspectFill
Self.canvasLayer.addSublayer Self.previewLayer
Self.CaptureSession.startRunning
End Sub
Property Private CaptureSession As AVCaptureSessionMBS
Property Private canvasLayer As CALayerMBS
Property Private previewLayer As AVCaptureVideoPreviewLayerMBS
End Class
Class LaunchScreen Inherits iosView
End Class
Class MyAVFoundationMBS Inherits AVFoundationMBS
EventHandler Sub captureOutputDidOutputMetadataObjects(captureOutput as AVCaptureOutputMBS, metadataObjects() as AVMetadataObjectMBS, connection as AVCaptureConnectionMBS)
If metadataObjects.Count > 0 Then
For Each obj As AVMetadataObjectMBS In metadataObjects
// Ad here your code to handle the read qr-code value
Dim Type As String = obj.Type
System.DebugLog "Type: " + Type
If Type = AVMetadataObjectMBS.AVMetadataObjectTypeQRCode Then
Dim Barcode As String = obj.stringValue
System.DebugLog "Found QR-Code: " + Barcode
If LastString <> Barcode Then
LastString = Barcode
MessageBox "Found QR-Code: "+Barcode
End If
End If
Next
End If
End EventHandler
Property Private LastString As string
End Class
ExternalFile info
End ExternalFile
End Project
The items on this page are in the following plugins: MBS AVFoundation Plugin.