netease_live_fluttify 0.1.1 copy "netease_live_fluttify: ^0.1.1" to clipboard
netease_live_fluttify: ^0.1.1 copied to clipboard

A `网易直播推流` flutter plugin, Powered by `Fluttify` engine.

example/lib/main.dart

import 'package:demo_widgets/demo_widgets.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:netease_live_fluttify/netease_live_fluttify.dart';
import 'package:permission_handler/permission_handler.dart';

const _testPushUrl = 你的推流地址;

Future<void> main() async {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: _HomeScreen());
  }
}

class _HomeScreen extends StatefulWidget {
  const _HomeScreen({
    Key key,
  }) : super(key: key);

  @override
  __HomeScreenState createState() => __HomeScreenState();
}

class __HomeScreenState extends State<_HomeScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
      ),
      body: FutureBuilder<bool>(
        future: [
          Permission.camera,
          Permission.microphone,
        ].request().then((it) =>
            it.values.every((status) => status == PermissionStatus.granted)),
        builder: (context, snapshot) {
          if (!snapshot.hasData) {
            return CupertinoActivityIndicator();
          } else {
            return _Live();
          }
        },
      ),
    );
  }
}

class _Live extends StatefulWidget {
  @override
  __LiveState createState() => __LiveState();
}

class __LiveState extends State<_Live> {
  LivePusher _pusher;
  double _strength = 0;
  double _smooth = 0;
  bool _flashOn = false;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        NeteaseView(
          onNeteaseViewCreated: (controller) async {
            _pusher = await LivePusher.create();
            await _pusher.initLiveStream(_testPushUrl);
            await _pusher.startVideoPreview(controller.playerView);
            await _pusher.startLiveStream();
          },
        ),
        Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[
            RaisedButton(
              onPressed: _handleSwitchCamera,
              child: Text('切换摄像头'),
            ),
            RaisedButton(
              onPressed: _handleStopPreview,
              child: Text('停止预览'),
            ),
            RaisedButton(
              onPressed: _handleResumePreview,
              child: Text('恢复推流/预览'),
            ),
            RaisedButton(
              onPressed: _handleStopStreaming,
              child: Text('停止推流'),
            ),
            DiscreteSetting(
              head: '设置滤镜 Android',
              options: [
                'none',
                'brooklyn',
                'clean',
                'fairytale',
                'nature',
                'healthy',
                'pixar',
                'tender',
                'whiten',
              ],
              onSelected: _handleSetFilterAndroid,
            ),
            DiscreteSetting(
              head: '设置滤镜 iOS',
              options: ['NORMAL', 'SEPIA', 'ZIRAN', 'MEIYAN1', 'MEIYAN2'],
              onSelected: _handleSetFilterIOS,
            ),
            RaisedButton(
              onPressed: _handleFlash,
              child: Text(_flashOn ? '关闭闪光灯' : '打开闪光灯'),
            ),
            Text('设置滤镜强度'),
            Slider(value: _strength, onChanged: _handleChangeStrength),
            Text('设置磨皮强度'),
            Slider(value: _smooth, onChanged: _handleChangeSmooth),
          ],
        ),
      ],
    );
  }

  @override
  void dispose() {
    _pusher.dispose();
    super.dispose();
  }

  void _handleSwitchCamera() async {
    await _pusher.switchCamera();
  }

  void _handleStopPreview() async {
    await _pusher.stopVideoPreview();
  }

  void _handleResumePreview() async {
    await _pusher.resumeLiveStream();
  }

  void _handleStopStreaming() async {
    await _pusher.stopLiveStreaming();
  }

  void _handleChangeStrength(double value) {
    setState(() {
      _strength = value;
      _pusher.setFilterStrength(value);
    });
  }

  void _handleChangeSmooth(double value) {
    setState(() {
      _smooth = value;
      _pusher.setSmoothLevel(value);
    });
  }

  void _handleSetFilterAndroid(String value) async {
    FilterTypeAndroid type;
    switch (value) {
      case 'none':
        type = FilterTypeAndroid.none;
        break;
      case 'brooklyn':
        type = FilterTypeAndroid.brooklyn;
        break;
      case 'clean':
        type = FilterTypeAndroid.clean;
        break;
      case 'fairytale':
        type = FilterTypeAndroid.fairytale;
        break;
      case 'nature':
        type = FilterTypeAndroid.nature;
        break;
      case 'healthy':
        type = FilterTypeAndroid.healthy;
        break;
      case 'pixar':
        type = FilterTypeAndroid.pixar;
        break;
      case 'tender':
        type = FilterTypeAndroid.tender;
        break;
      case 'whiten':
        type = FilterTypeAndroid.whiten;
        break;
    }
    await _pusher.setFilterType(
      filterTypeAndroid: type,
      filterTypeIOS: FilterTypeIOS.MEIYAN1,
    );
  }

  void _handleSetFilterIOS(String value) async {
    FilterTypeIOS type;
    switch (value) {
      case 'NORMAL':
        type = FilterTypeIOS.NORMAL;
        break;
      case 'SEPIA':
        type = FilterTypeIOS.SEPIA;
        break;
      case 'ZIRAN':
        type = FilterTypeIOS.ZIRAN;
        break;
      case 'MEIYAN1':
        type = FilterTypeIOS.MEIYAN1;
        break;
      case 'MEIYAN2':
        type = FilterTypeIOS.MEIYAN2;
        break;
    }
    await _pusher.setFilterType(
      filterTypeAndroid: FilterTypeAndroid.brooklyn,
      filterTypeIOS: type,
    );
  }

  void _handleFlash() {
    setState(() {
      _flashOn = !_flashOn;
      _pusher.flash(_flashOn);
    });
  }
}
0
likes
15
pub points
0%
popularity

Publisher

verified publisherfluttify.com

A `网易直播推流` flutter plugin, Powered by `Fluttify` engine.

Homepage

License

unknown (LICENSE)

Dependencies

flutter, foundation_fluttify

More

Packages that depend on netease_live_fluttify