0

In my android app, I have a video player where I will be using third-party SDKs for that. I am aiming to work with three different video player SDKs. As you know, each of these SDKs has its own properties. I have managed to unify using different SDKs by having an abstract factory design pattern. So each of these SDKs have been implemented in a separate class and I do have a "video player factory" which unifies the interface for these SDKs.

For example, in my code, I have something like this:

videoPlayer1 = VideoPlayerFactory.getVideoPlayer(new VideoPlayerFromSDK1);
videoPlayer2 = VideoPlayerFactory.getVideoPlayer(new VideoPlayerFromSDK2);

videoPlayer1.unifiedFunction();
videoPlayer2.unifiedFunction();

With this abstract factory design patter, I can have as much video player SDK as I want. However, the problem is that including all those SDKs is not logical in the app. What I would like to do is to build the app only with one of those SDKs (based on customers need) and the app realizes which SDK is included and what instance of video player should be used.

For example, if in the build I only include SDK1, then only the instance of that SDK is created and used.

Is that possible?

Mehdi Satei
  • 1,225
  • 9
  • 26

1 Answers1

0

Variant a) Define in your gradle file which dependencies should be included for which flavor of your app. Here is a similar question.

Variant b) Use modularization and dynamic feature delivery. You could design your app in a way where it would be shipped with no or one video player sdk. If a user needs to view a video with a specific sdk, a module containing that sdk could be downloaded by the app dynamically. (However, I haven't used this personally)

Google has an example for their Plaid App. In this app, you can read news from multiple sources. The logic to access a specific news site is capsuled in an own module which is only downloaded, if a user actually wants to access the news source for the first time. You can find the source code on github.

Alexander Hoffmann
  • 5,104
  • 3
  • 17
  • 23
  • Thanks, Alexander. I have read about the solution you provided. The important point here is that only one of these SDKs will be included in the Gradle. So for example, If SDK1 is only included, when I create an instance of video player, it should automatically use the related class. – Mehdi Satei Sep 24 '19 at 10:16