FffmpegPlugin.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.june.fffmpeg;
  2. import androidx.annotation.NonNull;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import io.flutter.embedding.engine.plugins.FlutterPlugin;
  6. import io.flutter.plugin.common.MethodCall;
  7. import io.flutter.plugin.common.MethodChannel;
  8. import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
  9. import io.flutter.plugin.common.MethodChannel.Result;
  10. import io.flutter.plugin.common.PluginRegistry.Registrar;
  11. /** FffmpegPlugin */
  12. public class FffmpegPlugin implements FlutterPlugin, MethodCallHandler {
  13. /// The MethodChannel that will the communication between Flutter and native Android
  14. ///
  15. /// This local reference serves to register the plugin with the Flutter Engine and unregister it
  16. /// when the Flutter Engine is detached from the Activity
  17. private MethodChannel channel;
  18. FlutterFFmpegResultHandler flutterFFmpegResultHandler;
  19. public FffmpegPlugin(){
  20. this.flutterFFmpegResultHandler = new FlutterFFmpegResultHandler();
  21. }
  22. @Override
  23. public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
  24. channel = new MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "fffmpeg");
  25. channel.setMethodCallHandler(this);
  26. }
  27. // This static function is optional and equivalent to onAttachedToEngine. It supports the old
  28. // pre-Flutter-1.12 Android projects. You are encouraged to continue supporting
  29. // plugin registration via this function while apps migrate to use the new Android APIs
  30. // post-flutter-1.12 via https://flutter.dev/go/android-project-migration.
  31. //
  32. // It is encouraged to share logic between onAttachedToEngine and registerWith to keep
  33. // them functionally equivalent. Only one of onAttachedToEngine or registerWith will be called
  34. // depending on the user's project. onAttachedToEngine or registerWith must both be defined
  35. // in the same class.
  36. public static void registerWith(Registrar registrar) {
  37. final MethodChannel channel = new MethodChannel(registrar.messenger(), "fffmpeg");
  38. channel.setMethodCallHandler(new FffmpegPlugin());
  39. }
  40. @Override
  41. public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
  42. if (call.method.equals("getPlatformVersion")) {
  43. result.success("Android " + android.os.Build.VERSION.RELEASE);
  44. } else if (call.method.equals("exeCommand")) {
  45. List<String> arguments = call.argument("arguments");
  46. final FlutterFFmpegExecuteFFmpegAsyncArgumentsTask asyncTask = new FlutterFFmpegExecuteFFmpegAsyncArgumentsTask(arguments, flutterFFmpegResultHandler, result);
  47. asyncTask.execute("dummy-trigger");
  48. }else {
  49. result.notImplemented();
  50. }
  51. }
  52. @Override
  53. public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
  54. channel.setMethodCallHandler(null);
  55. }
  56. }