我有这个代码:
@page "/Skaner"
@inject IJSRuntime JS
@using BlazorBarcodeScanner.ZXing.JS
<BarcodeReader Title="Skanuj kod kreskowy"
StartCameraAutomatically="true"
ShowStart="true"
ShowReset="true"
ShowToggleTorch="true"
ShowVideoDeviceList="true"
VideoWidth="300"
VideoHeight="200"
OnBarcodeReceived="HandleBarcodeReceived" />
@code {
private void HandleBarcodeReceived(BarcodeReceivedEventArgs args)
{
// Przetwarzaj zeskanowany kod
Console.WriteLine($"Zeskanowany kod: {args.BarcodeText}");
// Możesz dodać logikę do wyświetlenia lub przetworzenia zeskanowanego kodu
}
}
当我在 Windows 上运行它时,一切正常。 当我想在 Android 上运行它时,事情会变得更糟,因为它会说这样的话:“Skanuj kod kreskowy 无法枚举设备,方法不受支持。错误:无法枚举设备,方法不受支持。在 t.BrowserMultiFormatReader。 (http://192.168.0.78:8082/_content/BlazorBarcodeScanner.ZXing.JS/zxingjs.index.min.js:15:28105)在Generator.next()在http://192.168.0.78:8082/_content/ BlazorBarcodeScanner.ZXing.JS/zxingjs.index.min.js:15:27264 at new Promise () at P (http://192.168.0.78:8082/_content/BlazorBarcodeScanner.ZXing.JS/zxingjs.index.min.js :15:27009)在t.BrowserMultiFormatReader.listVideoInputDevices(http://192.168.0.78:8082/_content/BlazorBarcodeScanner.ZXing.JS/zxingjs.index.min.js:15:27944)在Object.listVideoInputDevices(http:/ /192.168.0.78:8082/_content/BlazorBarcodeScanner.ZXing.JS/BlazorBarcodeScanner.js:92:77) 在 http://192.168.0.78:8082/_framework/blazor.server.js:1:3047 在新的 Promise ()在 y.beginInvokeJSFromDotNet (http://192.168.0.78:8082/_framework/blazor.server.js:1:3004"
该应用程序由 Blazor Server 架构中的 IIS 托管。我使用它,他们的网站(例如在 Android 上)可以正常工作,即会打开一个请求使用相机许可的窗口。 https://www.nuget.org/packages/BlazorBarcodeScanner.ZXing.JS/#readme-body-tab https://www.nuget.org/packages/BlazorBarcodeScanner.ZXing.JS/#readme-body-tab
有什么提示为什么它不起作用吗?
我将其替换为 BlazorBarcodeScanner.ZXing.JS
@page "/SkanerXJ"
@using BlazorBarcodeScanner.ZXing.JS.Exceptions
@using BlazorBarcodeScanner.ZXing.JS
<h3>Skanowanie kodu kreskowego</h3>
<BlazorBarcodeScanner.ZXing.JS.BarcodeReader Title="Scan Barcode from Camera"
StartCameraAutomatically="false"
ShowStart="true"
ShowReset="true"
ShowToggleTorch="true"
ShowVideoDeviceList="true"
VideoWidth="600"
VideoHeight="480"
StreamWidth="1920"
StreamHeight="1080"
/>
<p>Ostatnio zeskanowany kod: @LastScannedCode</p>
@code {
private string LastScannedCode;
// Przykład metody do przypisania zeskanowanego kodu
private void OnBarcodeScanned(string barcode)
{
LastScannedCode = barcode;
Console.WriteLine("Zeskanowany kod: " + barcode);
}
}
It only reads 2D codes and I want 1D!!!