TheGwa
TheGwa

Reputation: 1889

Flutter share native objects between plugins

I am working on a couple plugins for streaming and recording video. In Android land it is generally not possible to have two things access the camera simultaneously.

The obvious solution is to merge the two plugins into one that marshals/shares the resource.

This got me thinking. Is there any way to share native objects between plugins? I cannot find any documentation or resources on this.

Does anyone have a suggestion on how to achieve this?

Upvotes: 5

Views: 467

Answers (1)

Pavlo Ostasha
Pavlo Ostasha

Reputation: 16699

I've been doing similar stuff - not with video but with raw data, and it is possible. There are two major approaches:

  1. Share data between the packages via flutter medium - method + event channels with the proper implementation in all plugins.
  2. Since you would have to implement a lot of boilerplate either way in both ios and android platforms, you as well may implement all the sharing directly in the native code. After all, you have access to all the plugins' native code in the native part of your flutter app. Just channel the data there correctly without including flutter at all(well, not at all - in the end, some trigger methods/events should exist either way).

I went down the second path, and it was not that hard to do. I'm not sure about your use case, but sharing the video stream between several end recipients is possible, so it should also be possible in the flutter app.

Upvotes: 1

Related Questions