4848import io .flutter .plugin .common .MethodCall ;
4949import io .flutter .plugin .common .MethodChannel ;
5050import io .flutter .plugin .common .MethodChannel .MethodCallHandler ;
51+ import io .flutter .plugin .common .BinaryMessenger ;
5152
5253/**
5354 * <h3>Flutter FFmpeg Plugin</h3>
@@ -94,14 +95,29 @@ public class FlutterFFmpegPlugin implements FlutterPlugin, MethodCallHandler, Ev
9495 private Context context ;
9596 private MethodChannel channel ;
9697 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" );
101112 channel .setMethodCallHandler (this );
102- eventChannel = new EventChannel (binding . getBinaryMessenger () , "flutter_ffmpeg_event" );
113+ eventChannel = new EventChannel (messenger , "flutter_ffmpeg_event" );
103114 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 ());
105121 }
106122
107123 @ Override
@@ -110,7 +126,7 @@ public void onDetachedFromEngine(final FlutterPluginBinding binding) {
110126 channel .setMethodCallHandler (null );
111127 channel = null ;
112128 }
113-
129+
114130 if (eventChannel != null ) {
115131 eventChannel .setStreamHandler (null );
116132 eventChannel = null ;
0 commit comments