mrtc_flutter 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 46

mrtc_flutter #

A new flutter plugin project.

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

1.0.0 #

This is a stream plugin by MuduCloud

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/cupertino.dart';
import 'resolutionRadio.dart';
import 'live.dart';
import 'package:mrtc_flutter/mrtc_flutter.dart';

void main() {
  SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight]);
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      home: Scaffold(
        body: SettingView(),
      ),
    );
  }
}

class SettingView extends StatelessWidget {
  final TextEditingController _controller = new TextEditingController();
  final FpsWidgt _fpsWidgt = FpsWidgt();
  String _resolution = '960x540';
  int _bitrate = 1000;

  @override
  Widget build(BuildContext context) {
    _controller.text = 'mrtc://test-mrtc.myun.tv/live/test';
    return new Container(
      width: double.infinity,
      height: double.infinity,
      padding: const EdgeInsets.all(10.0),
      decoration: BoxDecoration(image: DecorationImage(image: AssetImage('images/Background.png'),fit: BoxFit.fill)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Image(image: AssetImage('images/UrlPath.png'),),
              Container(width: 10,),
              Text('推流地址', style: TextStyle(color: Colors.grey),),
              Container(width: 10,),
              Expanded(child: Container(
                height: 30,
                padding: EdgeInsets.only(left: 10,right: 10),
                decoration: BoxDecoration(
                  color: Color.fromRGBO(0, 0, 0, 0.3),
                  borderRadius: BorderRadius.all(Radius.circular(15.0)),
                ),
                child: TextField(
                  controller: _controller,
                  maxLines: 1,
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 15,
                  ),
                  decoration: InputDecoration(
                    hintText: 'mrtc://',
                    hintStyle: TextStyle(
                      color: Colors.grey,
                      fontSize: 15,
                    ),
                    border: InputBorder.none,
                    contentPadding: EdgeInsets.all(5),
                  ),
                ),
              ),),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Image(image: AssetImage('images/BitRate.png'),),
              Container(width: 10,),
              Text('码率', style: TextStyle(color: Colors.grey),),
              Container(width: 10,),
              Text('500kbps', style: TextStyle(color: Colors.white),),
              Container(width: 10,),
              Expanded(child: BitrateSlider(
                min: 500,
                max: 2000,
                value: _bitrate,
                devisions: 30,
                onChanged: (int val){
                  _bitrate = val;
                },
              )),
              Container(width: 10,),
              Text('2000kbps', style: TextStyle(color: Colors.white),),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Image(image: AssetImage('images/Resolution.png'),),
              Container(width: 10,),
              Text('分辨率', style: TextStyle(color: Colors.grey),),
              Container(width: 10,),
              Container(
                width: 200,
                child:ResolutionRadioGroup(
                    values: ['480x360','960x540','1280x720'],
                    titleList: ['360P','540P','720P'],
                    defalutCheckedIndex: 1,
                    onChanged: _resolutionChanged
                ),),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Image(image: AssetImage('images/FrameRate.png'),),
              Container(width: 10,),
              Text('帧率', style: TextStyle(color: Colors.grey),),
              _fpsWidgt,
            ],
          ),

          Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              RaisedButton(
                onPressed: () {
                  List<String> strList = _resolution.split('x');
                  int videoW = int.parse(strList[0]);
                  int videoH = int.parse(strList[1]);
                  MRTCSetting setting = MRTCSetting(videoWidth: videoW,videoHeight: videoH,maxBitrate: _bitrate,fps: _fpsWidgt.fps);
                  Navigator.push(context, MaterialPageRoute(
                      builder: (BuildContext context) {
                        return LiveView(url: _controller.text, setting: setting);
                      }));
                },
                color: Colors.blue,
                textColor: Colors.white,
                child: Text('确定'),
              ),
            ],
          ),
        ],
      ),
    );
  }

  void _resolutionChanged(int index, String val) {
    _resolution = val;
  }
}

class BitrateSlider extends StatefulWidget {
  final int min;
  final int max;
  final int value;
  final Function(int val) onChanged;
  int devisions;
  BitrateSlider({@required this.min,@required this.max,@required this.value,@required this.onChanged,this.devisions}):assert(min <= value && max >= value);
  @override
  State<StatefulWidget> createState() {
    return BitrateSliderState(min.toDouble(),max.toDouble(),value.toDouble(),onChanged,devisions: devisions);
  }
}

class BitrateSliderState extends State<BitrateSlider> {
  double _val;
  double _min;
  double _max;
  Function(int val) _onChanged;
  int devisions;
  int _mVal;
  BitrateSliderState(this._min,this._max,this._val,this._onChanged,{this.devisions}):_mVal = _val.toInt();

  @override
  Widget build(BuildContext context) {
    return Slider(
      label: _mVal.toInt().toString()+'kbps',
      value: _mVal.toDouble(),
      min: _min,
      max: _max,
      divisions: devisions,
      onChanged: (double v){
        setState(() {
          setState(() {
            _mVal = v.toInt();
            _onChanged(_mVal);
          });
        });
      },
    );
  }
}

class FpsWidgt extends StatefulWidget {
  final FpsWidgtState _state = FpsWidgtState();
  @override
  State<StatefulWidget> createState() {
    return _state;
  }

  int get fps {
    return _state.fps;
  }
}

class FpsWidgtState extends State<FpsWidgt> {
  bool minusH = false;
  bool plusH = false;
  int fps = 25;
  final String _noramlMinusImgName = 'images/ClickMinus.png';
  final String _highlightMinusImgName = 'images/ClickMinus_h.png';
  final String _noramlPlusImgName = 'images/ClickPlus.png';
  final String _highlightPlusImgName = 'images/ClickPlus_h.png';
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          FlatButton(onPressed: _minusFps, child: Image(image: AssetImage(minusH?_highlightMinusImgName:_noramlMinusImgName)),onHighlightChanged:(bool flag){
            setState(() {
              minusH = flag;
            });
          },),
          Text('$fps',style: TextStyle(color: Colors.white),),
          FlatButton(onPressed: _plusFps, child: Image(image: AssetImage(plusH?_highlightPlusImgName:_noramlPlusImgName)),onHighlightChanged:(bool flag){
            setState(() {
              plusH = flag;
            });
          },),
        ],
      ),
    );
  }

  void _minusFps() {
    setState(() {
      if (fps == 10) {
        return;
      }else if (fps == 12){
        fps = 10;
      }else if (fps <= 15){
        fps -= 3;
      }else{
        fps -= 5;
      }
    });
  }

  void _plusFps() {
    setState(() {
      if (fps == 30) {
        return;
      }else if (fps >= 15){
        fps += 5;
      }else if (fps == 12){
        fps = 15;
      }else{
        fps += 2;
      }
    });
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  mrtc_flutter: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:mrtc_flutter/mrtc_flutter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

We analyzed this package on Apr 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

68 out of 68 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/mrtc_flutter.dart. (-0.50 points)

Analysis of lib/mrtc_flutter.dart reported 1 hint:

line 86 col 35: This function has a return type of 'Future', but doesn't end with a return statement.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test