|
1 | | -<!doctype html> |
| 1 | +<!DOCTYPE html> |
2 | 2 | <html lang="en"> |
3 | 3 |
|
4 | 4 | <head> |
5 | | - <meta charset="UTF-8"> |
6 | | - <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
7 | | - <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"> |
8 | | - <script src="./js/BridgeInitializer.js"></script> |
9 | | - <title>Android WebView Sample</title> |
| 5 | + <meta charset="utf-8"> |
| 6 | + <meta name="viewport" content="width=device-width,initial-scale=1.0"> |
| 7 | + <meta name="description" content="Quickly read barcodes with Dynamsoft Barcode Reader from a live camera stream."> |
| 8 | + <meta name="keywords" content="camera based barcode reading"> |
| 9 | + <link rel="canonical" href="https://demo.dynamsoft.com/Samples/DBR/JS/1.hello-world/14.read-video-webview.html"> |
| 10 | + <title>Dynamsoft Barcode Reader Sample - Read Video WebView(Android)</title> |
10 | 11 | </head> |
11 | 12 |
|
12 | | -<body style="margin: 0;"> |
13 | | - <header style="text-align: center; height: 100px; line-height: 100px;"> |
14 | | - <h1 style="margin: 0;">Android WebView</h1> |
15 | | - </header> |
16 | | - <hr style="margin: 0;"> |
17 | | - <div class="container" style="margin-top: 300px; padding: 0 10px; text-align: center; position: relative;"> |
18 | | - <i id="flash" |
19 | | - style="position: absolute; top: -80px; width: 30px; height: 30px; left: calc(50% - 15px); display: none;"> |
20 | | - <svg viewBox="64 64 896 896" data-icon="funnel-plot" width="1em" height="1em" fill="currentColor" |
21 | | - aria-hidden="true" focusable="false" class="" style="color: #fe8e14; font-size: 30px;"> |
22 | | - <path |
23 | | - d="M880.1 154H143.9c-24.5 0-39.8 26.7-27.5 48L349 607.4V838c0 17.7 14.2 32 31.8 32h262.4c17.6 0 31.8-14.3 31.8-32V607.4L907.7 202c12.2-21.3-3.1-48-27.6-48zM603.4 798H420.6V650h182.9v148zm9.6-226.6l-8.4 14.6H419.3l-8.4-14.6L334.4 438h355.2L613 571.4zM726.3 374H297.7l-85-148h598.6l-85 148z"> |
24 | | - </path> |
25 | | - </svg> |
26 | | - </i> |
27 | | - <button id="start" style="margin: 5px 0;">Start Scan</button> |
28 | | - <button id="stop" style="margin: 5px 0; display: none;">Stop Scan</button> |
29 | | - <h4 id="results"></h4> |
30 | | - <hr> |
31 | | - <span>Choose the Formats to Detect: </span> |
32 | | - <form id="chooseBarcodeFormats"> |
33 | | - <input type="checkbox" id="OneD" name="barcodeFormat" value="BF_ONED" checked> |
34 | | - <label for="OneD"> 1D </label><br /> |
35 | | - <input type="checkbox" id="QR" name="barcodeFormat" value="BF_QR_CODE" checked> |
36 | | - <label for="QR"> QR Code </label><br /> |
37 | | - <input type="checkbox" id="PDF417" name="barcodeFormat" value="BF_PDF417"> |
38 | | - <label for="PDF417"> PDF 417 </label><br /> |
39 | | - <input type="checkbox" id="Datamatrix" name="barcodeFormat" value="BF_DATAMATRIX"> |
40 | | - <label for="Datamatrix"> DataMatrix </label> <br /> |
41 | | - </form> |
42 | | - <span>Expected barcode count per frame: </span> |
43 | | - <input type="range" min="1" max="20" step="1" id="expectedNumberBarcodes" value="1"> |
44 | | - <span id="expectedNumberBarcodesLabel">1</span> |
| 13 | +<body style="margin: 0;padding: 0;"> |
| 14 | + <div id="UIElement" style="width: 100vw;height: 100vh;"> |
| 15 | + <span id='lib-load' style='font-size:x-large' hidden>Loading Library...</span> |
| 16 | + <div id="div-ui-container" class="div-ui-container"> |
| 17 | + <div class="dce-video-container"></div> |
| 18 | + </div> |
45 | 19 | </div> |
46 | | - |
| 20 | + <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/dbr.js"></script> |
47 | 21 | <script> |
48 | | - (async () => { |
49 | | - // set the position of the CameraView |
50 | | - // [marginLeft, marginTop, width, height] / px |
51 | | - dbrWebViewBridge.setCameraUI([window.screen.width / 2 - 125, 125, 250, 250]); |
52 | | - await updateBarcodeFormats(); |
53 | | - |
54 | | - dbrWebViewBridge.onBarcodeRead = results => { |
55 | | - let resultText = ""; |
56 | | - JSON.parse(results).forEach(result => { |
57 | | - resultText += result.barcodeText + " "; |
58 | | - }); |
59 | | - document.getElementById("results").innerText = resultText; |
60 | | - }; |
61 | | - })(); |
| 22 | + /** LICENSE ALERT - README |
| 23 | + * To use the library, you need to first specify a license key using the API "license" as shown below. |
| 24 | + */ |
62 | 25 |
|
63 | | - let flashFlag = false; |
64 | | - const startBtn = document.getElementById("start"); |
65 | | - const stopBtn = document.getElementById("stop"); |
66 | | - const flashBtn = document.getElementById("flash"); |
67 | | - const formatsForm = document.getElementById("chooseBarcodeFormats"); |
68 | | - const expectedRange = document.getElementById("expectedNumberBarcodes"); |
| 26 | + Dynamsoft.DBR.BarcodeReader.license = 'DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9'; |
69 | 27 |
|
70 | | - startBtn.addEventListener("click", () => { |
71 | | - startBtn.style.display = "none"; |
72 | | - flashBtn.style.display = "inline-block"; |
73 | | - stopBtn.style.display = "inline-block"; |
74 | | - dbrWebViewBridge.startScanning(); |
75 | | - }); |
76 | | - stopBtn.addEventListener("click", () => { |
77 | | - stopBtn.style.display = "none"; |
78 | | - flashBtn.style.display = "none"; |
79 | | - startBtn.style.display = "inline-block"; |
80 | | - dbrWebViewBridge.stopScanning(); |
81 | | - }); |
82 | | - flashBtn.addEventListener("click", () => { |
83 | | - dbrWebViewBridge.switchFlashlight(!flashFlag); |
84 | | - flashFlag = !flashFlag; |
85 | | - }); |
86 | | - formatsForm.addEventListener("change", async () => { |
87 | | - await updateBarcodeFormats(); |
88 | | - }); |
89 | | - expectedRange.addEventListener("change", async () => { |
90 | | - let expectedVal = document.getElementById('expectedNumberBarcodes').value; |
91 | | - document.getElementById('expectedNumberBarcodesLabel').innerText = expectedVal; |
92 | | - const settings = await dbrWebViewBridge.getRuntimeSettings(); |
93 | | - settings.expectedBarcodesCount = parseInt(expectedVal); |
94 | | - await dbrWebViewBridge.updateRuntimeSettings(settings); |
95 | | - }); |
| 28 | + /** |
| 29 | + * You can visit https://www.dynamsoft.com/customer/license/trialLicense?utm_source=github&product=dbr&package=js to get your own trial license good for 30 days. |
| 30 | + * Note that if you downloaded this sample from Dynamsoft while logged in, the above license key may already be your own 30-day trial license. |
| 31 | + * For more information, see https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=9.6.10&utm_source=github#specify-the-license or contact [email protected]. |
| 32 | + * LICENSE ALERT - THE END |
| 33 | + */ |
96 | 34 |
|
97 | | - async function updateBarcodeFormats() { |
98 | | - const EnumBarcodeFormat = await dbrWebViewBridge.getEnumBarcodeFormat(); |
99 | | - const settings = await dbrWebViewBridge.getRuntimeSettings(); |
100 | | - settings.barcodeFormatIds = EnumBarcodeFormat.BF_NULL; |
101 | | - const checkboxes = document.querySelectorAll('input[name="barcodeFormat"]:checked'); |
102 | | - checkboxes.forEach((checkbox) => { |
103 | | - switch (checkbox.value) { |
104 | | - case "BF_ONED": |
105 | | - settings.barcodeFormatIds |= EnumBarcodeFormat.BF_ONED; |
106 | | - break; |
107 | | - case "BF_QR_CODE": |
108 | | - settings.barcodeFormatIds |= EnumBarcodeFormat.BF_QR_CODE; |
109 | | - break; |
110 | | - case "BF_PDF417": |
111 | | - settings.barcodeFormatIds |= EnumBarcodeFormat.BF_PDF417; |
112 | | - break; |
113 | | - case "BF_DATAMATRIX": |
114 | | - settings.barcodeFormatIds |= EnumBarcodeFormat.BF_DATAMATRIX; |
115 | | - break; |
| 35 | + let pScanner = null; |
| 36 | + (async function () { |
| 37 | + try { |
| 38 | + await Dynamsoft.DBR.BarcodeReader.loadWasm(); |
| 39 | + window.DBR_Android.onWasmLoaded(); |
| 40 | + } catch (ex) { |
| 41 | + let errMsg; |
| 42 | + if (ex.message.includes("network connection error")) { |
| 43 | + errMsg = "Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support ([email protected]) to acquire an offline license."; |
| 44 | + } else { |
| 45 | + errMsg = ex.message || ex; |
116 | 46 | } |
117 | | - }); |
118 | | - await dbrWebViewBridge.updateRuntimeSettings(settings); |
| 47 | + console.error(errMsg); |
| 48 | + alert(errMsg); |
| 49 | + } |
| 50 | + })(); |
| 51 | + |
| 52 | + async function startScanner() { |
| 53 | + let scanner = await (pScanner = pScanner || Dynamsoft.DBR.BarcodeScanner.createInstance()); |
| 54 | + await scanner.setUIElement(document.getElementById('div-ui-container')); |
| 55 | + scanner.onUniqueRead = (txt, result) => { |
| 56 | + const format = result.barcodeFormatString; |
| 57 | + window.DBR_Android.onUniqueRead(format + " " + txt) |
| 58 | + }; |
| 59 | + await scanner.show(); |
119 | 60 | } |
120 | 61 |
|
| 62 | + async function stopScanner() { |
| 63 | + let scanner = await pScanner; |
| 64 | + scanner && scanner.hide(); |
| 65 | + } |
121 | 66 | </script> |
122 | 67 | </body> |
123 | 68 |
|
|
0 commit comments