api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.
This module is made for broadcasting RTMP live stream from smartphone camera.
In your pubspec.yaml file, add the following:
dependencies:
apivideo_live_stream: ^1.0.7
In your dart file, import the package:
import 'package:apivideo_live_stream/apivideo_live_stream.dart';
To be able to broadcast, you must:
- On Android: ask for internet, camera and microphone permissions:
<manifest>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
</manifest>
The library will require android.permission.CAMERA and android.permission.RECORD_AUDIO at runtime.
- On iOS: update the Info.plist with a usage description for camera and microphone
<key>NSCameraUsageDescription</key>
<string>Your own description of the purpose</string>
<key>NSMicrophoneUsageDescription</key>
<string>Your own description of the purpose</string>
- Creates a live stream controller
final LiveStreamController _controller = LiveStreamController();
- Initializes the live stream controller
await _controller.create(initialAudioConfig: AudioConfig(), initialVideoConfig: VideoConfig.withDefaultBitrate());
- Adds a CameraPreview widget as a child of your view
Ensure that _controller.create() has been finished before creating the CameraPreview widget.
child: CameraPreview(controller: _controller),
- Starts a live stream
_controller.startStreaming("YOUR_STREAM_KEY");
- Stops streaming and preview
_controller.stop();
On the application side, you must manage application lifecycle:
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.inactive) {
_controller.stop();
} else if (state == AppLifecycleState.resumed) {
_controller.startPreview();
}
}
You can try our example app, feel free to test it.
Be sure to follow the Flutter installation steps before anything.
- Open Android Studio
- File > New > Project from Version Control
In URL field, type:
[email protected]:apivideo/api.video-flutter-live-stream.git
Wait for the indexation to finish.
Connect an Android device to your computer and click on the Run main.dart
button.
-
Connect an iOS device to your computer and click on the
Run main.dart
button. -
The build will fail because you haven't set your development profile, sign your application:
Open Xcode, click on "Open a project or file" and open
the YOUR_PROJECT_NAME/example/ios/Runner.xcworkspace
file.
Click on Example, go in Signin & Capabilities
tab, add your team and create a unique bundle
identifier.
api.video Flutter live stream library is using external native library:
Plugin | README |
---|---|
StreamPack | StreamPack |
HaishinKit | HaishinKit |
If you have any questions, ask us here: https://community.api.video . Or use Issues.