Introduction
In this article, you will be provided with a step-by-step guide to building a video player with the Apollo SDK. Please contact Amino support to obtain the Apollo SDK file. With the SDK file, you can import the included AAR and AIDL library files to build your own video player.
Prerequisites
Android Studio: An IDE for Android app development.
Amino Media Player Device: The developed app can be run on any Amino Media Player device.
Apollo SDK File: A ZIP file will be provided containing the AAR and AIDL libraries, as well as a sample Android app project.
Summary
You are advised to install the latest version of Android Studio. The latest version of Android Studio will always provide you with the most up-to-date Android SDK resources, minimizing version dependencies when compiling your application.
Create A new Android Project
To create a test application for the Amino Media Player, select "Television" with "Empty Activity." A default project will be created by Android Studio with a main activity page containing empty content. Design the user interface of the main activity to present a sample player in your application.
Select the Android version that matches your Amino Media Player version. Your test application needs a minimum Android SDK version that is lower than or equal to the Android version of your Amino Media Player.
Import AAR player library
To run your sample application with the Amino SDK player, you need to import the player-related AAR (Android Archive Repository) library files into your Android Studio application project. Select the "Project" view in Android Studio. Create a "libs" directory under the root directory of your project.
Select "Open In" then "Explorer" to open the directory for the libs folder
Copy and place all the ExoPlayer and MediaPlayer AAR library files into the libs directory of your application project.
Configure Build Gradle file
Your application needs to know where and which library files need to be implemented. The configurations are written in the build.gradle file under the Gradle Scripts section of Android Studio. Specify the location of the AAR file to include it, which is defined under the dependencies section of the build.gradle file. The screenshot below shows an example:
Design the UI to present the Video ( On Activity_main.xml )
SurfaceView is used to display video content using the MediaPlayer class. It allows for drawing on a dedicated surface. PlayerView is a specialized view in ExoPlayer that provides built-in controls and functionality for video playback.
Create SufaceView for Mediaplayer
<SurfaceView
android:id="@+id/surfaceView1"
android:layout_width="match_parent"
android:layout_height="300dp"
android:clickable="true"
android:focusable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
Create VideoView for ExoPlayer
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="300dp"
android:clickable="false"
android:focusable="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
</com.google.android.exoplayer2.ui.PlayerView>
Import the class required for MediaPlayer ( On MainActivity )
To use the MediaPlayer class in your MainActivity, you'll need to import it at the top of your Java file. Here's the import statement:
import android.media.MediaPlayer;
Sample method for MediaPlayer Implementation
private synchronized void StartMediaPlayer() {
Uri default_uri = Uri.parse("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4");
mPlayer = new MediaPlayer();
mSurfaceView = findViewById(R.id.surfaceView1);
try {
mPlayer.setDataSource(default_uri.toString());
mPlayer.setDisplay(mSurfaceView.getHolder());
mPlayer.prepare();
mPlayer.start();
} catch (Exception e) {
e.printStackTrace();
}
Import the classes required for ExoPlayer ( On MainActivity )
To use ExoPlayer in your MainActivity, you'll need to import several classes. Here’s a summary of the required imports:
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.RawResourceDataSource;
import com.google.android.exoplayer2.ui.PlayerView;
Sample method for ExoPlayer Implementation
private void StartExoPlayer() {
Uri defaultUri = Uri.parse("http://dash.akamaized.net/dash264/TestCases/10a/1/iis_forest_short_poem_multi_lang_480p_single_adapt_aaclc_sidx.mpd");
ePlayer = new SimpleExoPlayer.Builder(context, new DefaultRenderersFactory(context)).build();
MediaSource eSource = createRawMediaSource(defaultUri);
ePlayer.prepare(eSource);
playerView.setPlayer(ePlayer);
ePlayer.setPlayWhenReady(true);
}
Starting the player on MainActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MainActivity.contextMain = getApplicationContext();
SurfaceView surfaceView = findViewById(R.id.surfaceView1);
PlayerView playerView = findViewById(R.id.video_view);
SimpleExoPlayer ePlayer;
MediaPlayer mPlayer;
StartExoPlayer();
StartMediaPlayer();
}
Build and test your Application
1. ADB connect your workstation to your Amino Media Player.
2. Select the device to build and test run your application.
3. Press the "PLAY" button to process the test build.
4. Once the test build success , the studio will launch your test APP on Amino Media Player .