Skip to content

teamtechackers/camera_pluging_flutter

Repository files navigation

usb_camera_plugin

A Flutter plugin for accessing and controlling USB cameras on Android devices. This plugin enables you to connect external USB cameras (UVC - USB Video Class) to your Flutter apps and access professional camera features.

Features

โœ… USB Camera Support - Connect and control external USB cameras (UVC compatible)
โœ… Real-time Preview - Display live camera feed in your Flutter app
โœ… Video Recording - Record videos in MP4 format with H.264 encoding
โœ… Image Capture - Take high-quality photos
โœ… Audio Support - Record audio with AAC encoding
โœ… Visual Effects - Apply effects like black & white, soul, zoom
โœ… Multiple Camera Types - Supports Camera1, Camera2, and UVC cameras
โœ… Professional Features - Resolution control, encoding options, and more

Platform Support

Platform Support
Android โœ… Yes
iOS โŒ No
Web โŒ No
Windows โŒ No
macOS โŒ No
Linux โŒ No

Requirements

  • Flutter SDK: >=3.3.0
  • Dart SDK: ^3.8.1
  • Android minSdkVersion: 24 (Android 7.0)
  • Android compileSdkVersion: 34
  • USB OTG support on your Android device
  • UVC compatible USB camera

Installation

๐Ÿ“ฆ Add to Your Project

The plugin now works in ANY Flutter project! ๐ŸŽ‰

Option 1: From Git (Recommended for now)

dependencies:
  usb_camera_plugin:
    git:
      url: https://github.com/teamtechackers/create_new_camara_plugin.git

Option 2: Local Path (for development)

dependencies:
  usb_camera_plugin:
    path: /path/to/camera_pluging_flutter_v1

Then run:

flutter pub get

๐ŸŽฏ Two Ways to Use

Choose based on your needs:

Option 1: Quick Integration (5 minutes)

Add plugin to any project for basic camera bridge functionality.

Option 2: Full Features (30 minutes) โญ RECOMMENDED

Get complete camera UI in YOUR project with all features:

  • โœ… USB Camera Detection - Automatic device discovery
  • โœ… Real-time Preview - Multiple resolution support
  • โœ… Video Recording - H.264/MP4 format
  • โœ… Photo Capture - High-quality images
  • โœ… Effects - Black & White, Soul, Zoom, and more
  • โœ… Audio Recording - AAC audio support
  • โœ… Settings & Controls - Brightness, contrast, resolution
  • โœ… Multi-camera Support - Switch between cameras
  • โœ… Professional UI - Modern, intuitive interface

Works in YOUR project with simple setup!


๐Ÿš€ Quick Start for YOUR Project (test_1, test_2, etc.)

Step 1: Run Auto-Setup Script

cd /Users/apple/AndroidStudioProjects/camera_pluging_flutter_v1
./setup_in_project.sh /Users/apple/AndroidStudioProjects/test_1

This copies all camera files to your project!

Step 2: Add to Your pubspec.yaml

dependencies:
  usb_camera_plugin:
    path: ../camera_pluging_flutter_v1

Step 3: Update Your build.gradle

Add to android/app/build.gradle:

android {
    compileSdk 34
    ndkVersion "27.0.12077973"
    
    defaultConfig {
        minSdk 24
        multiDexEnabled true
    }
    
    buildFeatures {
        viewBinding true
        dataBinding true
    }
}

dependencies {
    // Camera dependencies
    implementation 'com.afollestad.material-dialogs:core:3.2.1'
    implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2'
    implementation 'com.github.bumptech.glide:glide:4.10.0'
    implementation 'com.tencent:mmkv:1.2.12'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
}

Step 4: Update AndroidManifest

Add to android/app/src/main/AndroidManifest.xml:

<activity
    android:name="com.jiangdg.demo.MainActivity"
    android:exported="false"
    android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

Step 5: Use in Flutter!

import 'package:usb_camera_plugin/usb_camera_plugin.dart';

ElevatedButton(
  onPressed: () async {
    await UsbCameraPlugin().openCamera();
    // Full camera UI opens! ๐ŸŽ‰
  },
  child: Text('Open Camera'),
)

Done! Full camera features in YOUR app! ๐Ÿš€

๐Ÿ“– Detailed guide: See HOW_TO_USE_WITH_YOUR_PROJECT.md

๐Ÿš€ Quick Start

import 'package:usb_camera_plugin/usb_camera_plugin.dart';

// Create plugin instance
final _usbCameraPlugin = UsbCameraPlugin();

// Open camera
await _usbCameraPlugin.openCamera();

Android Setup

Add the following permissions to your AndroidManifest.xml:

<uses-feature android:name="android.hardware.usb.host" />
<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" />

Usage

Basic Example

import 'package:flutter/material.dart';
import 'package:usb_camera_plugin/usb_camera_plugin.dart';

class CameraScreen extends StatelessWidget {
  final _usbCameraPlugin = UsbCameraPlugin();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('USB Camera'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () async {
            try {
              await _usbCameraPlugin.openCamera();
            } catch (e) {
              print('Error opening camera: $e');
            }
          },
          child: Text('Open USB Camera'),
        ),
      ),
    );
  }
}

Get Platform Version

final plugin = UsbCameraPlugin();
String? version = await plugin.getPlatformVersion();
print('Platform version: $version');

API Reference

UsbCameraPlugin

Main class for interacting with USB cameras.

Methods

  • openCamera() - Opens the USB camera interface

    Future<void> openCamera()
  • getPlatformVersion() - Returns the Android platform version

    Future<String?> getPlatformVersion()

Compatible Devices

This plugin works with UVC (USB Video Class) compatible cameras, including:

  • External USB webcams
  • USB endoscope cameras
  • USB microscope cameras
  • Industrial USB cameras
  • Medical USB cameras
  • Most USB cameras that follow the UVC standard

Use Cases

  • ๐Ÿฅ Medical Applications - Endoscope and microscope integration
  • ๐Ÿญ Industrial Inspection - Quality control and monitoring
  • ๐Ÿ”ฌ Scientific Research - Laboratory equipment integration
  • ๐Ÿ“น Video Production - Professional camera integration
  • ๐ŸŽฎ Streaming Apps - External camera support
  • ๐Ÿ” Security Systems - Surveillance camera integration

Known Limitations

  • Currently supports Android only
  • Requires USB OTG support on the device
  • Some camera-specific features may not be available on all devices
  • iOS support is not available (iOS has restrictions on USB camera access)

Example App

Check out the example directory for a complete working app that demonstrates all features.

Troubleshooting

Camera not detected

  • Ensure your device supports USB OTG
  • Check that the USB camera is UVC compatible
  • Verify USB permissions are granted
  • Try reconnecting the camera

Permission errors

  • Make sure all required permissions are added to AndroidManifest.xml
  • Request runtime permissions for Android 6.0+

Build errors

  • Ensure minSdkVersion is at least 24
  • Run flutter clean and rebuild

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Credits

This plugin uses the following open-source libraries:

  • AndroidUSBCamera by jiangdg
  • libUVC - USB Video Class library
  • libjpeg-turbo - JPEG encoding/decoding
  • libusb - USB device access

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Author

Developed with โค๏ธ for the Flutter community.

Changelog

See CHANGELOG.md for a list of changes.

Support

If you find this plugin helpful, please give it a โญ๏ธ on GitHub!

For bugs and feature requests, please file an issue on the GitHub repository.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published