ContPlayer enables developers to implement the smooth experience of video/audio playing in a easy swipe style which is famous in TikTok and Reels kind of applications.
This implementation is designed into 2 modules.
a) contplayer-library-core : Handles core play-pause functionality of playing videos and maintain the player states on smooth scroll.
b) contplayer-library-ui : it offers the default customisable UI, implemented using ViewPager and displays the video items which are added into the player queue.
Step by Step guide to implement this code into your app :
- Clone this repository.
- To use core part of ContPlayer,
implementation project(':contplayer-library-core')
To use the ui part :
implementation project(':contplayer-library-ui')
- Add compile options into the build.gradle
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
-
Create a class which will implement the interface IContPlayerQueue and put the definitions of required functions.
-
Initiate the ContPlayer, IContPlayerQueue, ContPlayerCommandsanager in the below manner,
a) Init Object of ContPlayerView and set lifecycle owner as current activity or fragment
ContPlayerView contPlayerView = findViewById(R.id.contPlayerView);
contPlayerView.setLifecycleOwner(this);
b) Get the PlayerQueue feeded with player items
IContPlayerQueue contPlayerQueue = getStreamArrayList();
c) Initiate ContPlayerCommandsManager, it will take play, pause, release etc commands
ContPlayerCommandsManager contPlayerCommandsManager = new ContPlayerCommandsManager(this, contPlayerQueue);
d) set everything to ContPlayerView object
contPlayerView.setContPlayerCommandsManager(contPlayerCommandsManager);
contPlayerView.setResizeMode(Const.RESIZE_MODE_FILL);
contPlayerView.setPlayerQueue(contPlayerQueue);
e) start play of ContPlayer
new Handler().postDelayed(() -> contPlayerView.startPlay(), 300);
p.s. For any implementation doubts refer demo app, available in the same repository.