Flutter plugin for mofun flutter video.

main.dart 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:mofun_flutter_plugin_video/mofun_flutter_plugin_video.dart';
  5. import 'package:mofun_flutter_plugin_video/mofun_video_view.dart';
  6. void main() => runApp(MyApp());
  7. class MyApp extends StatefulWidget {
  8. @override
  9. _MyAppState createState() => _MyAppState();
  10. }
  11. class _MyAppState extends State<MyApp> {
  12. String _platformVersion = 'Unknown';
  13. @override
  14. void initState() {
  15. super.initState();
  16. initPlatformState();
  17. }
  18. // Platform messages are asynchronous, so we initialize in an async method.
  19. Future<void> initPlatformState() async {
  20. String platformVersion;
  21. // Platform messages may fail, so we use a try/catch PlatformException.
  22. try {
  23. platformVersion = await MofunFlutterPluginVideo.platformVersion;
  24. } on PlatformException {
  25. platformVersion = 'Failed to get platform version.';
  26. }
  27. // If the widget was removed from the tree while the asynchronous platform
  28. // message was in flight, we want to discard the reply rather than calling
  29. // setState to update our non-existent appearance.
  30. if (!mounted) return;
  31. setState(() {
  32. _platformVersion = platformVersion;
  33. });
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. const String defaultUrl = 'rtmp://live.hkstv.hk.lxdns.com/live/hks1';
  38. return MaterialApp(
  39. home: Scaffold(
  40. appBar: AppBar(
  41. title: const Text('Plugin example app'),
  42. ),
  43. body: Builder(builder: (context) {
  44. TextEditingController textEditingController =
  45. TextEditingController(text: defaultUrl);
  46. MofunVideoViewController controller;
  47. String url;
  48. return Column(
  49. children: <Widget>[
  50. Container(
  51. height: 400.0,
  52. child: MofunVideoView(
  53. onMofunVideoViewCreated: (c) {
  54. controller = c;
  55. c.toast('Mofun video!');
  56. },
  57. ),
  58. ),
  59. TextField(
  60. controller: textEditingController,
  61. onChanged: (s) => url = s),
  62. Row(
  63. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  64. children: <Widget>[
  65. RaisedButton(
  66. onPressed: () {
  67. controller?.play(url ?? defaultUrl);
  68. },
  69. child: Text('Play'),
  70. ),
  71. RaisedButton(
  72. onPressed: () {
  73. controller?.stop();
  74. },
  75. child: Text('Stop'),
  76. ),
  77. RaisedButton(
  78. onPressed: () {
  79. controller?.toast('暂不支持');
  80. },
  81. child: Text('Save'),
  82. ),
  83. ],
  84. ),
  85. Row(
  86. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  87. children: <Widget>[
  88. RaisedButton(
  89. onPressed: () {
  90. controller?.record();
  91. },
  92. child: Text('Record'),
  93. ),
  94. RaisedButton(
  95. onPressed: () {
  96. controller?.playerAndResume();
  97. },
  98. child: Text('PlayerAndResume'),
  99. ),
  100. ],
  101. ),
  102. ],
  103. );
  104. })),
  105. );
  106. }
  107. }