Frontend library for the Amplify Video Plugin.
New to AWS Amplify or Amplify Video? Consider following one of the tutorials or getting started guides first.
- Create a new Android Studio project with an Empty Activity.
- Give your project a name and finish project creation.
-
At the top level of your project directory, initialize an Amplify project and an Amplify Video live streaming resource. Follow the Getting Started with Live guide.
-
Open the the build.gradle script for your new app module.
- Modify the dependencies section to include amplify-android, amplify-android-extended and amplify-video-android:
dependencies {
// ... other depedencies ...
implementation 'com.amplifyframework:core:1.0.0'
implementation 'com.amplifyframework:extended:0.1.7'
implementation 'com.amplify-video:aws-video:0.1.9'
}
- Because Amplify Android uses Java 8 features, modify the android section to include these compile options:
android {
// ... other configuration ...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
- In the onCreate() method of your MainActivity class, initialize Amplify Extended with the Video plugin:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
AmplifyExtended.addCategory(new VideoCategory(), new VideoCategoryConfiguration(), "amplifyvideoconfiguration");
AmplifyExtended.addPlugin(AmplifyExtended.category("video"), new AWSVideoPlugin());
AmplifyExtended.configure(getApplicationContext());
} catch (AmplifyException error) {
Log.e("MyVideoApp", "Couldn't initialize Amplify Extended.");
}
}
- Add a VideoView to your app's layout. In
res/layout/activity_main.xml
, replace theTextView
with anAWSLiveVideoView
called myVideoView:
<com.amplifyframework.video.ui.AWSLiveVideoView
android:id="@+id/myVideoView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
- Add the internet permission to
manifests/AndroidManifest.xml
outside the<application>
tag:
<uses-permission android:name="android.permission.INTERNET" />
-
Extend your onCreate() method in the MainActivity class to attach your new view to an Amplify Video resource.
Replace mylivestream with the name you gave your new resource at Step 3. You can use
amplify status
to list all of your project resources.
// ... code to initialize Amplify Extended ...
AWSLiveVideoView videoView = findViewById(R.id.myVideoView);
AWSLiveVideoPlayer player = videoView.getPlayer();
VideoCategory amplifyVideo = AmplifyExtended.category("video");
LiveResource videoResource = amplifyVideo.getLiveResource("mylivestream");
player.attach(videoResource);
player.play();
-
If you haven't already, begin streaming to the MediaLive ingest URI provided by Amplify Video.
The URI can be viewed again by using
amplify video get-info
. -
Launch your app and view the live stream.
To be notified about player events, implement the VideoPlayer.Listener
interface and register your listener:
player.addListener(myListener);
Supported events:
- State Change (to any of Idle, Preparing, Ready, Playing, Buffering, Ended)
- Preparing
- Ready
- Seek
- Play
- Pause
- Buffering Start
- Buffering Complete
- Playback End
- Screen Touch
To enable sending analytics events to AWS Pinpoint, you must add the analytics category to your project.
- From your project's root directory, use the Amplify CLI tool to add analytics.
$ amplify add analytics
- Accept the default prompts and provision the AWS resources.
$ amplify push
- Modify the initialization of Amplify Extended in your MainActivity class to also initialize Amplify with the analytics and auth categories.
try {
AmplifyExtended.addCategory(new VideoCategory(), new VideoCategoryConfiguration(), "amplifyvideoconfiguration");
AmplifyExtended.addPlugin(AmplifyExtended.category("video"), new AWSVideoPlugin());
AmplifyExtended.configure(getApplicationContext());
Amplify.addPlugin(new AWSCognitoAuthPlugin());
Amplify.addPlugin(new AWSPinpointAnalyticsPlugin(new Application()));
Amplify.configure(getApplicationContext());
} catch (AmplifyException error) {
Log.e("MyVideoApp", "Couldn't initialize Amplify and Amplify Extended.");
}
- Provide a copy of your analytics category to the Amplify Video player at any time to enable all default analytics:
player.addAnalytics(Amplify.Analytics);
Any class that extends VideoView
can be used to display Amplify Video streams (even VideoView
itself).
- Instead of adding an
AWSLiveVideoView
to yourres/layout/activity_main.xml
file, replace it with aVideoView
.
<VideoView
android:id="@+id/myVideoView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
- Instead of the code from Step 10 in Getting Started above, attach the player to your view like this:
// ... code to initialize Amplify Extended ...
AWSLiveVideoView videoView = findViewById(R.id.myVideoView);
AWSLiveVideoPlayer player = new AWSLiveVideoPlayer(videoView); // <-- different
VideoCategory amplifyVideo = AmplifyExtended.category("video");
LiveResource videoResource = amplifyVideo.getLiveResource("mylivestream");
player.attach(videoResource);
player.play();
This library is licensed under the Apache 2.0 License.
We appreciate your feedback -- comments, questions, and bug reports. Please submit a GitHub issue.
Please see the Contributing Guidelines.