Flutter SDK for building a realtime broadcaster using the Millicast platform. This Software Development Kit (SDK) for Flutter allows developers to simplify Millicast services integration into their own Android and iOS apps.
The Flutter project template adds it, so it may already be there. You will also need to set your build settings to Java 8, because the official WebRTC jar now uses static methods in EglBase interface. Just add this to your app level build.gradle:
If necessary, in the same build.gradle you will need to increase minSdkVersion of defaultConfig up to 21 (currently default Flutter generator set it to 16).
Basic Usage
This is a simple Minimum V P of our project to show the publish or subscribing features. You will need to put the following three code snippets in the respective main.dart, publisher.dart and viewer.dart files, and set your Millicast streaming credentials where needed in order to test it.
Main app
import'publisher.dart';
import'viewer.dart';
import'package:flutter_webrtc/flutter_webrtc.dart';
import'package:flutter/material.dart';
const type =String.fromEnvironment('type');
voidmain() async {
runApp(constMyApp());
}
classMyAppextendsStatelessWidget {
constMyApp({Key? key}) :super(key: key);
// This widget is the root of your application.@overrideWidgetbuild(BuildContext context) {
returnMaterialApp(
title:'Millicast SDK Demo',
theme:ThemeData(
primarySwatch:Colors.purple,
),
home:constMyHomePage(title:'Millicast SDK Demo'),
);
}
}
classMyHomePageextendsStatefulWidget {
constMyHomePage({Key? key, requiredthis.title}) :super(key: key);
finalString title;
@overrideState<MyHomePage>createState() =>_MyHomePageState();
}
class_MyHomePageStateextendsState<MyHomePage> {
finalRTCVideoRenderer _localRenderer =RTCVideoRenderer();
@overridevoiddispose() {
_localRenderer.dispose();
super.dispose();
}
@overridevoidinitState() {
initRenderers();
// Run application with --dart-define type flag like:// flutter run --dart-define=type="subscribe||publish"// To choose wether you want to publishe or subscribe.switch (type) {
case'subscribe':subscribeExample();
break;
case'publish':publishExample();
break;
default:publishExample();
}
super.initState();
}
voidpublishExample() async {
awaitpublishConnect(_localRenderer);
setState(() {});
}
voidsubscribeExample() async {
awaitviewConnect(_localRenderer);
setState(() {});
}
voidinitRenderers() async {
await _localRenderer.initialize();
}
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
appBar:AppBar(
// Here we take the value from the MyHomePage object that was created by// the App.build method, and use it to set our appbar title.
title:Text(widget.title),
),
body:OrientationBuilder(
builder: (context, orientation) {
returnRotatedBox(
quarterTurns:1,
child:Center(
child:Container(
margin:constEdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
width:MediaQuery.of(context).size.width,
height:MediaQuery.of(context).size.height,
child:RTCVideoView(_localRenderer, mirror:true),
decoration:constBoxDecoration(color:Colors.black54),
),
));
},
),
);
}
}
Publisher app
import'dart:io';
import'package:flutter_webrtc/flutter_webrtc.dart';
import'package:millicast_flutter_sdk/millicast_flutter_sdk.dart';
FuturepublishConnect(RTCVideoRenderer localRenderer) async {
// Setting subscriber optionsDirectorPublisherOptions directorPublisherOptions =DirectorPublisherOptions(
token:'my-publishing-token', streamName:'my-stream-name');
/// Define callback for generate new tokentokenGenerator() =>Director.getPublisher(directorPublisherOptions);
/// Create a new instancePublish publish =Publish(streamName:'my-streamname', tokenGenerator: tokenGenerator);
finalMap<String, dynamic> constraints =<String, bool>{
'audio':true,
'video':true
};
MediaStream stream =await navigator.mediaDevices.getUserMedia(constraints);
localRenderer.srcObject = stream;
//Publishing OptionsMap<String, dynamic> broadcastOptions = {'mediaStream': stream};
//Some Android devices do not support h264 codec for publishingif (Platform.isAndroid) {
broadcastOptions['codec'] ='vp8';
}
/// Start connection to publishertry {
await publish.connect(options: broadcastOptions);
return publish.webRTCPeer;
} catch (e) {
throwException(e);
}
}
I've been tinkering around with the flutter SDK for Millicast and I'm running into an expected identifier issue when I try to import the millicastFlutterSDK:
which seems to be an issue in the peer_connection.dart line 303:
I'm developing on Windows w/Vs Code, Flutter: 3.0.1. Let me know if this is a local issue or related to the SDK.
Any plans (or target date) on when this library would support Flutter Desktop and Linux specifically? That would be tremendous for the work we are doing.
After i used command
-flutter pub add millicast-flutter-sdk
I got an error which is
-Because kandack depends on millicast-flutter-sdk any which doesn't exist (could not find package millicast-flutter-sdk at https://pub.dartlang.org), version solving failed.
This is the first beta test release of the Millicast Flutter SDK.
For SDK usage instructions, please refer to the SDK README.md.
An Example App (EA) at flutter-sdk/example has been provided to illustrate the basic usage of the SDK.
Usage of the EA is documented at its own readme at flutter-sdk/example/README.md.
There are some known issues as indicated below that are currently being worked on.
Known issues:
H264 publish on Android is device dependent.
Possible workaround includes publishing with other codecs, such as VP8, VP9.
The EA has some minor issues:
On iOS, the first publish might be missing audio.
Possible workaround is to exit, reenter Publisher view, and publish again.
Viewer count might not work correctly in some scenarios.
Subscription occasionally does not terminate after leaving Subscriber view.
Possible workaround is to restart EA.
Full Changelog: https://github.com/millicast/flutter-sdk/commits/0.1.0