Toro
Video list auto playback made simple, specially built for RecyclerView
Releases
Please grab latest demo APK and see release note here
Menu
- Features
- Demo
- Getting start, basic implementation
- Proguard
- Advance topics
- Contribution
- Support
- Hall of Fame
- License
Features
Core:
- Auto start/pause Media playback on user interaction: scroll, open/close App.
- Optional playback position save/restore (default: disabled).
- If enabled, Toro will also save/restore them on Configuration change (orientation change, multi-window mode ...).
- Customizable playback component: either MediaPlayer or ExoPlayer will work. Toro comes with default helper classes to support these 2.
- Customizable player selector: custom the selection of the player to start, among many other players.
- Which in turn support single/multiple players.
- Powerful default implementations, enough for various use cases.
Plus alpha:
- First class support for ExoPlayer 2.
Demo (Youtube Video)
Getting start, basic implementation
1. Update module build.gradle.
ext {
latest_release = '3.6.2.2804' // TODO check above for latest version
}
dependencies {
implementation "im.ene.toro3:toro:${latest_release}"
implementation "im.ene.toro3:toro-ext-exoplayer:${latest_release}" // to get ExoPlayer support
}
Using snapshot:
Update this to root's build.gradle
allprojects {
repositories {
google()
jcenter()
// Add url below to use snaphot
maven { url 'https://oss.jfrog.org/artifactory/oss-snapshot-local' }
}
// TODO anything else
}
Application's build.gradle
ext {
latest_snapshot = '3.7.0.2901-SNAPSHOT' // TODO check above for latest version
// below: other dependencies' versions maybe
}
dependencies {
implementation "im.ene.toro3:toro:${latest_snapshot}"
implementation "im.ene.toro3:toro-ext-exoplayer:${latest_snapshot}" // to get ExoPlayer support
}
2. Using Container
in place of Video list/RecyclerView.
<im.ene.toro.widget.Container
android:id="@+id/my_fancy_videos"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
3. Implement ToroPlayer
to ViewHolder that should be a Video player.
Sample ToroPlayer implementation (click to expand)
public class SimpleExoPlayerViewHolder extends RecyclerView.ViewHolder implements ToroPlayer {
static final int LAYOUT_RES = R.layout.vh_exoplayer_basic;
@Nullable ExoPlayerViewHelper helper;
@Nullable private Uri mediaUri;
@BindView(R.id.player) PlayerView playerView;
SimpleExoPlayerViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
// called from Adapter to setup the media
void bind(@NonNull RecyclerView.Adapter adapter, Uri item, List<Object> payloads) {
if (item != null) {
mediaUri = item;
}
}
@NonNull @Override public View getPlayerView() {
return playerView;
}
@NonNull @Override public PlaybackInfo getCurrentPlaybackInfo() {
return helper != null ? helper.getLatestPlaybackInfo() : new PlaybackInfo();
}
@Override
public void initialize(@NonNull Container container, @Nullable PlaybackInfo playbackInfo) {
if (helper == null) {
helper = new ExoPlayerViewHelper(this, mediaUri);
}
helper.initialize(container, playbackInfo);
}
@Override public void release() {
if (helper != null) {
helper.release();
helper = null;
}
}
@Override public void play() {
if (helper != null) helper.play();
}
@Override public void pause() {
if (helper != null) helper.pause();
}
@Override public boolean isPlaying() {
return helper != null && helper.isPlaying();
}
@Override public boolean wantsToPlay() {
return ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= 0.85;
}
@Override public int getPlayerOrder() {
return getAdapterPosition();
}
}
More advanced View holder implementations can be found in
app, demo-xxx module.