dump_video_action.dart 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import 'dart:io';
  2. import 'package:agora_rtc_engine/agora_rtc_engine.dart';
  3. import 'package:agora_rtc_engine/agora_rtc_engine_debug.dart';
  4. import 'package:flutter/foundation.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:path_provider/path_provider.dart';
  7. import 'log_sink.dart';
  8. class DumpVideoAction extends StatefulWidget {
  9. const DumpVideoAction({Key? key, required this.rtcEngine}) : super(key: key);
  10. final RtcEngine rtcEngine;
  11. @override
  12. State<DumpVideoAction> createState() => _DumpVideoActionState();
  13. }
  14. class _DumpVideoActionState extends State<DumpVideoAction> {
  15. bool _startDumpVideo = false;
  16. @override
  17. Widget build(BuildContext context) {
  18. if (!(defaultTargetPlatform == TargetPlatform.windows ||
  19. defaultTargetPlatform == TargetPlatform.macOS)) {
  20. return Container();
  21. }
  22. return Column(
  23. mainAxisSize: MainAxisSize.min,
  24. mainAxisAlignment: MainAxisAlignment.start,
  25. crossAxisAlignment: CrossAxisAlignment.start,
  26. children: [
  27. ElevatedButton(
  28. onPressed: () async {
  29. _startDumpVideo = !_startDumpVideo;
  30. Directory appDocDir = await getApplicationDocumentsDirectory();
  31. if (_startDumpVideo) {
  32. widget.rtcEngine.startDumpVideo(
  33. VideoSourceType.videoSourceCamera.value(),
  34. appDocDir.absolute.path,
  35. );
  36. logSink.log('Video data has dump to ${appDocDir.absolute.path}');
  37. } else {
  38. widget.rtcEngine.stopDumpVideo();
  39. }
  40. setState(() {});
  41. },
  42. child: Text('${_startDumpVideo ? 'Stop' : 'Start'} dump video'),
  43. ),
  44. ],
  45. );
  46. }
  47. }