Skip to content

1. Toro in Practice A Beginner Guide

Nam Nguyen Hoai edited this page Oct 23, 2016 · 1 revision

This wiki will guide you through the very basic usage of Toro. A more advance usage can be found in Demo application.

This tutorial assumes that you have enough knowledge about Android, Android API level, ability to implement a simple RecyclerView in either an Activity or a Fragment.

This tutorial takes Basic Sample 1 as the code base, please take a look at it while reading this.

1. Preparation: Target Android version, prefer Playback API.

  • Toro supports Android from 16 up, so be careful if your App must go down to 15 or lower.

  • There are 3 built-in extensions by each supports one Playback API: ExoPlayer 2, ExoPlayer 1, Android MediaPlayer and 1 build-in extensions built on top of ExoPlayer 2 Extension with more advance usabilities. Based on your need and your prefer API, you can choose one of them, or either Create your own.

2. Setup your Application.

3. Build your first RecyclerView Video list.

  • 3.1 Your Activity/Fragment: In Basic Sample 1, I use the Activity/Fragment combination. But you can always remove the Fragment and apply corresponding actions in Fragment to the Activity.

  • 3.2 Your Video data source: Basic Sample 1 uses static content as Video source. In real practice, you may prefer to have dynamic contents, obtain from either an API or some sort of local files (Device's media library for example). Any of them is OK, the point is to have the Media URI to feed your VideoView/ViewHolder. See this and this for more information.

    • Important: If you query Medias from Device storage, you must request the android.permission.READ_EXTERNAL_STORAGE permission at run time.
  • 3.3 Your Adapter/ViewHolder combination: normally, I implement the Adapter and ViewHolder a long with each other, ViewHolder is done first, then Adapter. The reason is: ViewHolder creation is a part of Adapter behaviour. And ViewHolder need to know which type of data that Adapter provides it.

In this case, I define all the layout first, then write the Basic1VideoViewHolder, apply all behaviour I want for a Video view. It extends the ExoVideoViewHolder so you will be prompted to implement some methods. The non-Video ViewHolder is done as usual (just like any other ViewHolder).

After that, I write Basic1Adapter, define when to return a Video and when not to. That will results in different viewType which will be used to create suitable ViewHolder.

  • 3.4 Your RecyclerView: setup your RecyclerView with your Adapter and a normal LinearLayoutManager. Refer to Wiki: Toro starting guide and Basic1ListFragment.java to register your RecyclerView.

Finally, start your Application and see if it works.

Clone this wiki locally