πΈ Live MJPEG Streaming in Flutter: A Complete Guide
π Introduction
Are you looking to integrate real-time MJPEG video streaming into your Flutter app? Whether youβre working with security cameras, IoT devices, or live monitoring applications, MJPEG streaming is a powerful and efficient way to handle video feeds. In this tutorial, weβll explore how to use the mjpeg_stream package to display real-time video in Flutter effortlessly. π₯π‘
π₯ Why MJPEG Streaming?
β
Easy Integration β Works seamlessly with IP cameras & MJPEG sources. β
Customizable UI β Add overlays, watermarks, and blur sensitive content. β
Cross-Platform β Works on Android, iOS, and Web.
β
Low Latency β Ensures near-instant live streaming
β
Lightweight & Efficient β No need for heavy video codecs like H.264 or WebRTC.
π¦ Getting Started
πΉ Step 1: Install the Package
To add mjpeg_stream
to your Flutter project, run:
flutter pub add mjpeg_stream
πΉ Step 2: Import the Package
import 'package:mjpeg_stream/mjpeg_stream.dart';
πΉ Step 3: Implement MJPEG Streaming
import 'package:flutter/material.dart';
import 'package:mjpeg_stream/mjpeg_stream.dart';
void main() {
runApp(MyApp());
}class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text("MJPEG Stream Example")),
body: Center(
child: MJPEGStreamScreen(
streamUrl: "http://your-ip-camera-url/video.mjpg",
width: 300.0,
height: 200.0,
fit: BoxFit.cover,
showLiveIcon: true,
showWatermark: true,
watermarkText: "My Stream",
blurSensitiveContent: false,
),
),
),
);
}
}
π¨ Customization Options
Property Type Default Description streamUrl
String
Required MJPEG stream URL. width
double
double.infinity
Stream display width. height
double
300.0
Stream display height. fit
BoxFit
BoxFit.cover
Controls how the image fits. showLiveIcon
bool
false
Displays a "LIVE" badge. showWatermark
bool
false
Adds a watermark overlay. watermarkText
String
"MJPEG Stream"
Custom watermark text. blurSensitiveContent
bool
false
Blurs sensitive content.
π Advanced Features
π Blur Sensitive Content
blurSensitiveContent: true,
π·οΈ Adding a Watermark
showWatermark: true,
watermarkText: "Protected Stream",
π¬ Showing a Live Indicator
showLiveIcon: true,
π Troubleshooting
π΄ Stream Not Loading? Ensure your MJPEG source is accessible. β‘ Slow Performance? Try a lower resolution stream. π₯ App Crashing? Implement better error handling.
π Use Cases
π₯ IP Camera Streaming
π¨ Security & Surveillance
π‘ Remote Monitoring & IoT
πΊ Live Dashboard Displays
π Resources
- π¦ Pub.dev: MJPEG Stream Package
- π GitHub: MJPEG Stream Repo
- π₯ Demo Video: MJPEG Stream in Action
π° Support My Work
If you found this tutorial useful, consider supporting my work:
- β Buy Me a Coffee: Support Here