AVMetadataMachineReadableCodeObject
AVMetadataMachineReadableCodeObject represents a code recognized in the captured picture, such as a QR code or a product barcode. Besides the inherited type and position, it carries the code's text (stringValue) and the code's four corners (corners).
It comes from the detect event of AVCaptureMetadataOutput. The element type of the event's objects is the parent class AVMetadataObject, so check with instanceof AVMetadataMachineReadableCodeObject before reading the code's fields.
Like its parent class, it's a read-only value. Assigning to a field throws TypeError with a message such as stringValue is read-only (verified by testing).
It belongs to the @nacrejs/av-capture package; for installation, see AVCaptureSession.
Inheritance: AVMetadataObject → AVMetadataMachineReadableCodeObject
Constructor
Can't be created with new; it throws TypeError with the message Illegal constructor: AVMetadataObject comes from the detect event of AVCaptureMetadataOutput (verified by testing).
Instance properties
Also inherits type and bounds from AVMetadataObject.
| Property | Description |
|---|---|
stringValue read-only | The code's text. null when the content isn't text |
corners read-only | The code's four corners, as an array of CGPoint |
Instance methods
None.
Examples
const output = new AVCaptureMetadataOutput();
output.addEventListener('detect', (e) => {
for (const found of e.objects) {
if (found instanceof AVMetadataMachineReadableCodeObject && found.stringValue !== null) {
console.log(found.type + ' ' + found.stringValue + ', ' + found.corners.length + ' corners');
}
}
});Effect: When scanning a QR code, it prints a line every frame, for example qrCode https://example.com/a, 4 corners. Verified by testing: a recognized QR code has type 'qrCode' and 4 points in corners.
Corresponding iOS API
AVMetadataMachineReadableCodeObject. stringValue is the same; corners is an array of dictionaries in ObjC and an array of CGPoint here.
See also
AVMetadataObject: the parent class,typeandboundsdetect- Draw a box around each code