Plays multiple media(videos or whiteboards) at the same time with synchronized progress and speed. Stops when the longest media ended.
AtomPlayer
: Abstract class for anything that is playable.VideoPlayer
: ForExoPlayer
supported media.WhiteboardPlayer
: For Netless Whiteboard replay room.OffsetPlayer
: Add blank offset before anAtomPlayer
.SelectionPlayer
: Cherry-pick segments of anAtomPlayer
.SyncPlayer
: Factory class for grouping AtomPlayers.
- Android SDK Version >= 21
- Android Tools Build >= 4.1.0
// project build
allprojects {
repositories {
// ...
maven { url 'https://jitpack.io' }
}
}
// app build
android {
// ...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation "com.github.netless-io:sync-player-android:1.2.1"
}
You may clone this repo and run the app.
example ClusterPlayerActivity
class Example {
private void initPlayer() {
VideoPlayer videoPlayer1 = new VideoPlayer(this, Constant.ALL_VIDEO_URL[0]);
// Note: videoPlayer need a container to display
videoPlayer1.setPlayerContainer(playerContainer1);
VideoPlayer videoPlayer2 = new VideoPlayer(this, Constant.ALL_VIDEO_URL[1]);
videoPlayer2.setPlayerContainer(playerContainer2);
AtomPlayer finalPlayer = new ClusterPlayer(videoPlayer1, videoPlayer2);
finalPlayer.addPlayerListener(new AtomPlayerListener() {
});
finalPlayer.play();
}
}
You may add a time offset before any AtomPlayer
:
class Example {
private void initPlayer() {
VideoPlayer videoPlayer = new VideoPlayer(this, Constant.ALL_VIDEO_URL[0]);
AtomPlayer finalPlayer = new OffsetPlayer(videoPlayer, 5000L);
finalPlayer.addPlayerListener(new AtomPlayerListener() {
});
finalPlayer.play();
}
}
example OffsetPlayerActivity
You may trim any AtomPlayer
to selected parts by providing a selection list.
class Example {
private void initPlayer() {
VideoPlayer videoPlayer = new VideoPlayer(this, Constant.ALL_VIDEO_URL[1]);
AtomPlayer finalPlayer = new SelectionPlayer(
videoPlayer,
new SelectionOptions(Arrays.asList(
new Selection(5_000, 10_000),
new Selection(15_000, 20_000),
new Selection(30_000, 40_000),
new Selection(60_000, 100_000))
)
);
finalPlayer.addPlayerListener(new AtomPlayerListener() {
});
finalPlayer.play();
}
}
example SelectionPlayerActivity
Sync videos with Netless Whiteboard Replay.
class Example {
private void onWhitePlayerReady(Player player) {
AtomPlayer videoPlayer = new VideoPlayer(this, Constant.ALL_VIDEO_URL[1]);
AtomPlayer selectionPlayer = new SelectionPlayer(new WhiteboardPlayer(player), new SelectionOptions(
Arrays.asList(
new Selection(5_000, 10_000),
new Selection(15_000, 20_000),
new Selection(30_000, 40_000),
new Selection(60_000, 120_000)
)
));
AtomPlayer finalPlayer = new ClusterPlayer(selectionPlayer, videoPlayer);
finalPlayer.addPlayerListener(new AtomPlayerListener() {
});
finalPlayer.play();
}
}
see example WhiteSelectionClusterPlayerActivity
All apis see AtomPlayer
atomPlayer.play();
atomPlayer.pause();
atomPlayer.stop();
atomPlayer.seekTo(200);
Duration(in millisecond) of the longest media.
Player progress time(in millisecond).
Player playback speed.
Player status. see AtomPlayer.AtomPlayerPhase
Idle
Player init status or error statusReady
Player can play immediately.Pause
Player paused by user invokingplayer.pause()
.Playing
Player is playing.Buffering
Player is buffering.Ended
Player ends.
A function create a AtomPlayer to play grouping AtomPlayers
class Example {
private void code() {
AtomPlayer atomPlayer = SyncPlayer.combine(atomPlayer1, atomPlayer2, atomPlayer3,...);
}
}
A builder create AtomPlayer for less temporary AtomPlayer statement.
Note: here some constraints
- AtomPlayerBuilder can only create one VideoPlayer or one WhiteboardPlayer once.
- AtomPlayerBuilder only store one offset and one selection record.
class Example {
private void createWithNewOperator(Player player) {
AtomPlayer videoPlayer = new VideoPlayer(this, Constant.ALL_VIDEO_URL[1]);
videoPlayer.setPlayerContainer(playerContainer);
WhiteboardPlayer whiteboardPlayer = new WhiteboardPlayer(player);
SelectionPlayer selectionPlayer = new SelectionPlayer(whiteboardPlayer,
new SelectionOptions(Arrays.asList(
new Selection(5_000, 10_000),
new Selection(15_000, 20_000),
new Selection(30_000, 40_000),
new Selection(60_000, 720_000)
)));
finalPlayer = SyncPlayer.combine(selectionPlayer, videoPlayer);
}
private void createWithAtomPlayerBuilder(Player player) {
AtomPlayer videoPlayer = new AtomPlayerBuilder()
.video(this, Constant.ALL_VIDEO_URL[1])
.setPlayerContainer(playerContainer)
.create();
AtomPlayer whiteboardPlayer = new AtomPlayerBuilder()
.whiteboard(player)
.selection(new SelectionOptions(Arrays.asList(
new Selection(5_000, 10_000),
new Selection(15_000, 20_000),
new Selection(30_000, 40_000),
new Selection(60_000, 720_000)
)))
.create();
finalPlayer = SyncPlayer.combine(whiteboardPlayer, videoPlayer);
}
}