USB 摄像头适配iPadOS17+

This commit is contained in:
2026-10-22 12:53:24 +08:00
parent 582242e9aa
commit 58a23ef218
18 changed files with 288 additions and 140 deletions

View File

@@ -39,6 +39,9 @@ public class UsbCameraAndroidPlugin implements FlutterPlugin, MethodChannel.Meth
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
switch (call.method) {
case "isSupported":
result.success(true);
break;
case "getDeviceList":
result.success(engine.getDeviceList());
break;

View File

@@ -46,6 +46,19 @@ class UsbCameraAndroid {
return _eventStream!;
}
/// 当前平台/设备是否支持 USB(UVC)摄像头。
/// - Android:始终 true。
/// - iOS:仅 iPadOS 17+ 的 iPad 为 true;iPhone 或 iOS<17 为 false。
/// 通道未注册(异常)时保守返回 true,交由上层继续走原有枚举/错误流程。
static Future<bool> isSupported() async {
try {
final result = await _methodChannel.invokeMethod('isSupported');
return result as bool? ?? true;
} catch (_) {
return true;
}
}
/// 枚举当前连接的 UVC 设备。
static Future<List<UsbCameraDeviceInfo>> getDeviceList() async {
final List<dynamic> result =

View File

@@ -1,7 +1,8 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
/// Android 原生 UVC 预览画面。
/// 原生 UVC 预览画面(Android: AndroidView / iOS: UiKitView)。
class UsbCameraPreviewView extends StatelessWidget {
const UsbCameraPreviewView({super.key});
@@ -9,6 +10,13 @@ class UsbCameraPreviewView extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (defaultTargetPlatform == TargetPlatform.iOS) {
return const UiKitView(
viewType: _viewType,
layoutDirection: TextDirection.ltr,
creationParamsCodec: StandardMessageCodec(),
);
}
return const AndroidView(
viewType: _viewType,
layoutDirection: TextDirection.ltr,

View File

@@ -13,6 +13,8 @@ flutter:
android:
package: com.maibu.usb_camera_android
pluginClass: UsbCameraAndroidPlugin
ios:
pluginClass: UsbCameraAndroidPlugin
dependencies:
flutter:

View File

@@ -0,0 +1,20 @@
# video\_player\_android
The Android implementation of [`video_player`][1].
## Usage
This package is [endorsed][2], which means you can simply use `video_player`
normally. This package will be automatically included in your app when you do,
so you do not need to add it to your `pubspec.yaml`.
However, if you `import` this package to use any of its APIs directly, you
should add it to your `pubspec.yaml` as usual.
## Known issues
Using `VideoViewType.platformView` is not currently recommended on Android due to a known [issue][3] affecting platform views on Android.
[1]: https://pub.dev/packages/video_player
[2]: https://flutter.dev/to/endorsed-federated-plugin
[3]: https://github.com/flutter/flutter/issues/164899

View File

@@ -0,0 +1,9 @@
# Platform Implementation Test App
This is a test app for manual testing and automated integration testing
of this platform implementation. It is not intended to demonstrate actual use of
this package, since the intent is that plugin clients use the app-facing
package.
Unless you are making changes to this implementation package, this example is
very unlikely to be relevant.