flutter_uvc_camera 0.0.2
flutter_uvc_camera: ^0.0.2 copied to clipboard
Flutter plugin, allowing apps in the Flutter project to use UVC cameras connected to the device.
flutter_uvc_camera #
A Flutter plugin based on AndroidUSBCamera to enable Flutter apps to use external cameras.
pub.dev link:https://pub.dev/packages/flutter_uvc_camera
Getting Started #
1. Add Dependency #
Add the flutter_uvc_camera
plugin dependency to your Flutter project's pubspec.yaml
file:
dependencies:
flutter_uvc_camera: last_version
2. Configure Android Project #
Before using this plugin, some configurations are needed for the Android project.
Add Permissions #
Add the following permissions to the AndroidManifest.xml file of your Android project:
<uses-permission android:name="android.permission.USB_PERMISSION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-feature android:name="android.hardware.usb.host" />
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<!-- Add other necessary permissions here -->
Add maven { url "https://jitpack.io" } in android/build.gradle:
allprojects {
repositories {
///其他仓库
maven { url "https://jitpack.io" }
}
}
Add Intent Filter and Meta-data for Device Insertion Detection, Plug-in Monitoring, and Recognition of Opening Applications
Add an action for USB device connection in the intent-filter of mainActivity, and reference the corresponding XML file in meta-data:
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
<?xml version="1.0" encoding="utf-8"?>
<usb>
<usb-device vendor-id="11111" product-id="22222" />
</usb>
3. Usage Example #
import 'package:flutter/material.dart';
import 'package:flutter_uvc_camera/uvc_camera_controller.dart';
import 'package:flutter_uvc_camera/uvc_camera_view.dart';
class CameraTest extends StatefulWidget {
const CameraTest({super.key});
@override
State<CameraTest> createState() => _CameraTestState();
}
class _CameraTestState extends State<CameraTest> {
UVCCameraController? cameraController;
@override
void initState() {
super.initState();
cameraController = UVCCameraController();
cameraController?.msgCallback = (state) {
showCustomToast(state);
};
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('UVC Camera Example'),
),
body: Center(
child: UVCCameraView(
cameraController: cameraController!,
width: 300,
height: 300),
),
),
);
}
}
Notes #
- Ensure that the required permissions are configured before using the plugin, otherwise the plugin may not function properly.
- The plugin currently supports using external cameras in Flutter projects but may have some limitations and compatibility issues. Please test and adjust the plugin according to your needs.
Issue Reporting #
If you encounter any problems or have any suggestions during usage, please report them on [GitHub Issues] (https://github.com/chenyeju295/flutter_uvc_camera/issues) .