FlutterFFmpegExecuteAsyncCommandTask.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2019 Taner Sener
  3. *
  4. * This file is part of FlutterFFmpeg.
  5. *
  6. * FlutterFFmpeg is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * FlutterFFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with FlutterFFmpeg. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.arthenica.flutter.ffmpeg;
  20. import android.os.AsyncTask;
  21. import android.util.Log;
  22. import com.arthenica.mobileffmpeg.FFmpeg;
  23. import io.flutter.plugin.common.MethodChannel;
  24. /**
  25. * Asynchronous task which performs {@link FFmpeg#execute(String, String)} method invocations.
  26. *
  27. * @author Taner Sener
  28. * @since 0.1.0
  29. */
  30. public class FlutterFFmpegExecuteAsyncCommandTask extends AsyncTask<String, Integer, Integer> {
  31. private String delimiter;
  32. private final MethodChannel.Result result;
  33. private final FlutterFFmpegResultHandler flutterFFmpegResultHandler;
  34. FlutterFFmpegExecuteAsyncCommandTask(final FlutterFFmpegResultHandler flutterFFmpegResultHandler, final String delimiter, final MethodChannel.Result result) {
  35. if (delimiter == null) {
  36. this.delimiter = " ";
  37. } else {
  38. this.delimiter = delimiter;
  39. }
  40. this.result = result;
  41. this.flutterFFmpegResultHandler = flutterFFmpegResultHandler;
  42. }
  43. @Override
  44. protected Integer doInBackground(final String... strings) {
  45. int rc = -1;
  46. if ((strings != null) && (strings.length > 0)) {
  47. final String command = strings[0];
  48. Log.d(FlutterFFmpegPlugin.LIBRARY_NAME, String.format("Running FFmpeg command: %s with delimiter %s.", command, delimiter));
  49. rc = FFmpeg.execute(command, delimiter);
  50. Log.d(FlutterFFmpegPlugin.LIBRARY_NAME, String.format("FFmpeg exited with rc: %d", rc));
  51. }
  52. return rc;
  53. }
  54. @Override
  55. protected void onPostExecute(final Integer rc) {
  56. flutterFFmpegResultHandler.success(result, FlutterFFmpegPlugin.toIntMap(FlutterFFmpegPlugin.KEY_RC, rc));
  57. }
  58. }