FlutterFFmpegResultHandler.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.june.fffmpeg;
  20. import android.os.Handler;
  21. import android.os.Looper;
  22. import io.flutter.plugin.common.EventChannel;
  23. import io.flutter.plugin.common.MethodChannel;
  24. /**
  25. * <h3>Flutter FFmpeg Result Handler</h3>
  26. *
  27. * @author Taner Sener
  28. * @since 0.2.2
  29. */
  30. class FlutterFFmpegResultHandler {
  31. private final Handler handler;
  32. FlutterFFmpegResultHandler() {
  33. handler = new Handler(Looper.getMainLooper());
  34. }
  35. void notImplemented(final MethodChannel.Result result) {
  36. handler.post(new Runnable() {
  37. @Override
  38. public void run() {
  39. if (result != null) {
  40. result.notImplemented();
  41. }
  42. }
  43. });
  44. }
  45. void success(final MethodChannel.Result result, final Object object) {
  46. handler.post(new Runnable() {
  47. @Override
  48. public void run() {
  49. if (result != null) {
  50. result.success(object);
  51. }
  52. }
  53. });
  54. }
  55. void success(final EventChannel.EventSink eventSink, final Object object) {
  56. handler.post(new Runnable() {
  57. @Override
  58. public void run() {
  59. if (eventSink != null) {
  60. eventSink.success(object);
  61. }
  62. }
  63. });
  64. }
  65. }