Camera and Microphone streaming library via RTMP for Flutter.

Overview

HaishinKit Plugin

pub package

  • A Flutter plugin for iOS, Android. Camera and Microphone streaming library via RTMP.
Android iOS
Support SDK 21+ iOS 9.0+

🌏 Dependencies

Project name Notes License
HaishinKit for iOS, macOS and tvOS. Camera and Microphone streaming library via RTMP, HLS for iOS, macOS and tvOS. BSD 3-Clause "New" or "Revised" License
HaishinKit for Android. Camera and Microphone streaming library via RTMP for Android. BSD 3-Clause "New" or "Revised" License

🎨 Features

RTMP

  • Authentication
  • Publish and Recording (H264/AAC)
  • Playback (Beta)
  • Adaptive bitrate streaming
    • Automatic drop frames
  • Action Message Format
    • AMF0
    • AMF3
  • SharedObject
  • RTMPS
    • Native (RTMP over SSL/TLS)

🐾 Example

Here is a small example flutter app displaying a camera preview.

import 'dart:async';

import 'package:audio_session/audio_session.dart';
import 'package:flutter/material.dart';
import 'package:haishin_kit/audio_source.dart';
import 'package:haishin_kit/net_stream_drawable_texture.dart';
import 'package:haishin_kit/rtmp_connection.dart';
import 'package:haishin_kit/rtmp_stream.dart';
import 'package:haishin_kit/video_source.dart';
import 'package:permission_handler/permission_handler.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  RtmpConnection? _connection;
  RtmpStream? _stream;
  bool _recording = false;
  CameraPosition currentPosition = CameraPosition.back;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    await Permission.camera.request();
    await Permission.microphone.request();

    // Set up AVAudioSession for iOS.
    final session = await AudioSession.instance;
    await session.configure(const AudioSessionConfiguration(
      avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
      avAudioSessionCategoryOptions:
      AVAudioSessionCategoryOptions.allowBluetooth,
    ));

    RtmpConnection connection = await RtmpConnection.create();
    connection.eventChannel.receiveBroadcastStream().listen((event) {
      switch (event["data"]["code"]) {
        case 'NetConnection.Connect.Success':
          _stream?.publish("live");
          setState(() {
            _recording = true;
          });
          break;
      }
    });
    RtmpStream stream = await RtmpStream.create(connection);
    stream.attachAudio(AudioSource());
    stream.attachVideo(VideoSource(position: currentPosition));

    if (!mounted) return;

    setState(() {
      _connection = connection;
      _stream = stream;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('HaishinKit example app'), actions: [
          IconButton(
            icon: const Icon(Icons.flip_camera_android),
            onPressed: () {
              if (currentPosition == CameraPosition.front) {
                currentPosition = CameraPosition.back;
              } else {
                currentPosition = CameraPosition.front;
              }
              _stream?.attachVideo(VideoSource(position: currentPosition));
            },
          )
        ]),
        body: Center(
          child: _stream == null
              ? const Text("")
              : NetStreamDrawableTexture(_stream),
        ),
        floatingActionButton: FloatingActionButton(
          child: _recording
              ? const Icon(Icons.fiber_smart_record)
              : const Icon(Icons.not_started),
          onPressed: () {
            if (_recording) {
              _connection?.close();
              setState(() {
                _recording = false;
              });
            } else {
              _connection?.connect("rtmp://192.168.1.9/live");
            }
          },
        ),
      ),
    );
  }
}
You might also like...

An example of "reactive/streaming repository" as a solution for BLoC to BLoC communication

An example of

Reactive Repositories An example of listening to a Stream from repository layer (instead of explicitly using get/fetch) as a solution for BLoC to BLoC

Sep 13, 2022

Face Mask Detection mobile application built with Flutter and TensorFlow lite in order to detect face masks using images and live camera.

Face Mask Detection mobile application built with Flutter and TensorFlow lite in order to detect face masks using images and live camera.

Face Mask Detector App Face Mask Detection mobile application built with Flutter and TensorFlow lite in order to detect face masks using images and li

Aug 15, 2022

Real-time object detection in Flutter using camera and tflite plugin

Real-time object detection in Flutter using camera and tflite plugin

For details: https://medium.com/@shaqian629/real-time-object-detection-in-flutter-b31c7ff9ef96 flutter_realtime_detection Real-time object detection i

Jul 21, 2022

its just take image from gallery or camera and save to file (in flutter)

flutter_img_pdf A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

Dec 28, 2021

A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

r_scan A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your iss

Sep 9, 2022

This is a flutter plugin to detect edges in a live camera, take the picture of detected edges object, crop it, and save.

This is a flutter plugin to detect edges in a live camera, take the picture of detected edges object, crop it, and save.

edge_detection A flutter plugin to detect edges of objects, scan paper, detect corners, detect rectangles. It allows cropping of the detected object i

Sep 18, 2022

💳 A Flutter package for making payments via credo central. Provides support for both Android and iOS

💳 Credo Package for Flutter TODO: Put a short description of the package here that helps potential users know whether this package might be useful fo

Dec 26, 2021

A Dart Build Plugin that uploads debug symbols for Android, iOS/macOS and source maps for Web to Sentry via sentry-cli

Sentry Dart Plugin A Dart Build Plugin that uploads debug symbols for Android, iOS/macOS and source maps for Web to Sentry via sentry-cli. For doing i

Sep 5, 2022

Multi-Camera-Dashboard - Flutter App to View RTSP Streams

Multi-Camera-Dashboard - Flutter App to View RTSP Streams

9.9.2021 update I have updated the firebase db to be read only due to abuse. The save operation works if you import your own firebase and modify proje

Sep 15, 2022
Comments
  • Cannot connect to Mux RTMP secure server URL

    Cannot connect to Mux RTMP secure server URL

    Describe the bug

    Thank you for all of your work on your excellent product.

    I use your example Flutter code in debug mode to try to connect via an iPhone 11 to a Mux RTMP server secure URL e.g. rtmps://global-live.mux.com:443/app/MUX STREAM KEY and the response after attempting to connect is always "NetConnection.Connect.Closed". I test the same URL on the iPhone using Larix and it works fine.

    To Reproduce

    1. Use your example Flutter code
    2. Edit pubspec.yml to use haishin_kit 0.9.1
    3. Use a Mux secure URL e.g. rtmps://global-live.mux.com:443/app/MUX STREAM KEY
    4. Observe that is does not connect

    Expected behavior

    To connect and broadcast

    Version

    haishin_kit 0.9.1

    Smartphone info.

    • Device: iPhone 11
    • OS: iOS 15.5

    Additional context

    No response

    Screenshots

    No response

    Relevant log output

    No response

    opened by DaleBeckles 0
  • Unsupported code error

    Unsupported code error

    image
    Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unsupported value for standard codec'
    
    Unsupported value: [] of type __SwiftValue
    *** Assertion failure in -[FlutterStandardWriter writeValue:], FlutterStandardCodec.mm:338
    *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unsupported value for standard codec'
    *** First throw call stack:
    (0x1b13c1288 0x1ca0bb744 0x1b2c4e360 0x10a673478 0x10a6735ac 0x10a6735ac 0x10a673b00 0x10a6712fc 0x105bc5c50 0x105bc5388 0x105bc5454 0x1b1352834 0x1b13eefd4 0x1b13c21d0 0x1b13688ac 0x1b2b37754 0x1065913bc 0x1065914c8 0x10665ccf0 0x106652038 0x106652644 0x106652644 0x106652788 0x10667efe0 0x10661afd0 0x10661bcac 0x10661c2f8 0x1b142c120 0x1b144917c 0x1b1026e6c 0x1b1028a30 0x1b1030124 0x1b1030c80 0x1b103b500 0x222c800bc 0x222c7fe5c)
    libc++abi: terminating with uncaught exception of type NSException
    * thread #34, queue = 'com.haishinkit.HaishinKit.NetSocket.input', stop reason = signal SIGABRT
        frame #0: 0x00000001e8f56b38 libsystem_kernel.dylib`__pthread_kill + 8
    libsystem_kernel.dylib`__pthread_kill:
    ->  0x1e8f56b38 <+8>:  b.lo   0x1e8f56b58               ; <+40>
        0x1e8f56b3c <+12>: pacibsp 
        0x1e8f56b40 <+16>: stp    x29, x30, [sp, #-0x10]!
        0x1e8f56b44 <+20>: mov    x29, sp
    Target 0: (Runner) stopped.
    
    opened by Hansrider 6
Releases(0.9.1)
Flutter plugin for selecting images from the Android and iOS image library, taking new pictures with the camera, and edit them before using such as rotation, cropping, adding sticker/text/filters.

advance_image_picker Flutter plugin for selecting multiple images from the Android and iOS image library, taking new pictures with the camera, and edi

Weta Vietnam 89 Sep 22, 2022
QR.Flutter is a Flutter library for simple and fast QR code rendering via a Widget or custom painter.

QR.Flutter is a Flutter library for simple and fast QR code rendering via a Widget or custom painter. Need help? Please do not submit an issue for a "

Yakka 600 Sep 16, 2022
Pancake is an android streaming app for movies, for movies, tv-shows and anime.

Pancake Pancake is an android streaming app for movies, for movies, tv-shows and anime. Feature Ad free, No Ads whatsoever No tracking/analytics Insta

tejas 10 Sep 18, 2022
Flutterbodydetection - A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmentation APIs for both static images and live camera stream.

body_detection A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmen

null 14 Sep 15, 2022
An app to pick, upload and display images from camera and gallery with size and extension constraints.

image_uploader A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

Ehmad Saeed⚡ 4 Mar 7, 2022
Flutter plugin to simply integrate Agora Video Calling or Live Video Streaming to your app with just a few lines of code.

Agora UI Kit for Flutter Instantly integrate Agora video calling or video streaming into your Flutter application. Getting started Requirements An Ago

Agora.io Community 102 Sep 25, 2022
A streaming client for the Komga self-hosted comics/manga/BD server targeting Android/iOS written in Dart/Flutter

Klutter A streaming client for the Komga self-hosted comics/manga/BD server targeting Android/iOS written in Dart/Flutter Background This is a project

Mark Winckle 53 Sep 17, 2022
An sample app demonstrating online radio streaming in flutter

Flutter Radio App Hey, This is an app demonstarting online radio streaming in flutter. Have a look. Demo Catch the demo in this video. If you like it,

Aman gautam 24 Jun 28, 2022
Netflix redesign - Redesign a Netflix movie streaming app UI With Flutter

Redesign Netflix App Packages http jiffy cached_network_image flutter_svg carous

tustoz 20 Sep 13, 2022
Flutter plugin for playing or streaming YouTube videos inline using the official iFrame Player API

Flutter plugin for playing or streaming YouTube videos inline using the official iFrame Player API. The package exposes almost all the API provided by iFrame Player API. So, it's 100% customizable.

Pratap Singh 0 May 15, 2022