/SyncPlayer

A Simple SyncPlayer for Whiteboard

Primary LanguageJavaMIT LicenseMIT

SyncPlayer

Plays multiple media(videos or whiteboards) at the same time with synchronized progress and speed. Stops when the longest media ended.

Overview

  • AtomPlayer: Abstract class for anything that is playable.
    • VideoPlayer: For ExoPlayer supported media.
    • WhiteboardPlayer: For Netless Whiteboard replay room.
    • OffsetPlayer: Add blank offset before an AtomPlayer.
    • SelectionPlayer: Cherry-pick segments of an AtomPlayer.
    • SyncPlayer: Factory class for grouping AtomPlayers.

Environment

Requirements

  • Android SDK Version >= 21
  • Android Tools Build >= 4.1.0

build.gradle

// 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.0.0-beta.1"
}

Usage

You may clone this repo and run the app.

Basic

see example ClusterPlayerActivity

class Example {
    private void initPlayer() {
        VideoPlayer videoPlayer1 = new VideoPlayer(this, Constant.ALL_VIDEO_URL[0]);
        VideoPlayer videoPlayer2 = new VideoPlayer(this, Constant.ALL_VIDEO_URL[1]);

        AtomPlayer finalPlayer = new ClusterPlayer(videoPlayer1, videoPlayer2);
        finalPlayer.addPlayerListener(new AtomPlayerListener() {
        });
        finalPlayer.play();
    }
}

Offset

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();
    }
}

see example OffsetPlayerActivity

Selection Player

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();
    }
}

see example SelectionPlayerActivity

Sync With Netless Whiteboard

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 = SyncPlayer.combine(selectionPlayer, videoPlayer);
        finalPlayer.addPlayerListener(new AtomPlayerListener() {
        });
        finalPlayer.play();
    }

}

see example WhiteSelectionClusterPlayerActivity

API

All apis see AtomPlayer

play

atomPlayer.play();

pause

atomPlayer.pause();

stop

atomPlayer.stop();

seekTo

atomPlayer.seekTo(200);

duration

Duration(in millisecond) of the longest media.

currentPosition

Player progress time(in millisecond).

status

Player status. see AtomPlayer.AtomPlayerPhase

  • Idle Player init status or error status
  • Ready Player can play immediately.
  • Pause Player paused by user invoking player.pause().
  • Playing Player is playing.
  • Buffering Player is buffering.
  • Ended Player ends.