48
48
import io .flutter .plugin .common .MethodCall ;
49
49
import io .flutter .plugin .common .MethodChannel ;
50
50
import io .flutter .plugin .common .MethodChannel .MethodCallHandler ;
51
+ import io .flutter .plugin .common .BinaryMessenger ;
51
52
52
53
/**
53
54
* <h3>Flutter FFmpeg Plugin</h3>
@@ -94,14 +95,29 @@ public class FlutterFFmpegPlugin implements FlutterPlugin, MethodCallHandler, Ev
94
95
private Context context ;
95
96
private MethodChannel channel ;
96
97
private EventChannel eventChannel ;
97
-
98
- @ Override
99
- public void onAttachedToEngine (final FlutterPluginBinding binding ) {
100
- channel = new MethodChannel (binding .getBinaryMessenger (), "flutter_ffmpeg" );
98
+
99
+ /**
100
+ * Registers plugin to registry.
101
+ *
102
+ * @param registrar receiver of plugin registration
103
+ */
104
+ @ SuppressWarnings ("deprecation" )
105
+ public static void registerWith (final io .flutter .plugin .common .PluginRegistry .Registrar registrar ) {
106
+ FlutterFFmpegPlugin flutterFFmpegPlugin = new FlutterFFmpegPlugin ();
107
+ flutterFFmpegPlugin .init (registrar .messenger (), (registrar .activity () != null ) ? registrar .activity () : registrar .context ());
108
+ }
109
+
110
+ private void init (final BinaryMessenger messenger , final Context context ) {
111
+ channel = new MethodChannel (messenger , "flutter_ffmpeg" );
101
112
channel .setMethodCallHandler (this );
102
- eventChannel = new EventChannel (binding . getBinaryMessenger () , "flutter_ffmpeg_event" );
113
+ eventChannel = new EventChannel (messenger , "flutter_ffmpeg_event" );
103
114
eventChannel .setStreamHandler (this );
104
- context = binding .getApplicationContext ();
115
+ this .context = context ;
116
+ }
117
+
118
+ @ Override
119
+ public void onAttachedToEngine (final FlutterPluginBinding binding ) {
120
+ init (binding .getBinaryMessenger (), binding .getApplicationContext ());
105
121
}
106
122
107
123
@ Override
@@ -110,7 +126,7 @@ public void onDetachedFromEngine(final FlutterPluginBinding binding) {
110
126
channel .setMethodCallHandler (null );
111
127
channel = null ;
112
128
}
113
-
129
+
114
130
if (eventChannel != null ) {
115
131
eventChannel .setStreamHandler (null );
116
132
eventChannel = null ;
0 commit comments