Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Examine the code

Focus mode
Examine the code - Amazon Kinesis Video Streams

In this section of the Android producer library procedure, you examine the example code.

The Android test application (AmazonKinesisVideoDemoApp) shows the following coding pattern:

  • Create an instance of KinesisVideoClient.

  • Create an instance of MediaSource.

  • Start streaming. Start the MediaSource, and it starts sending data to the client.

The following sections provide details.

Create an instance of KinesisVideoClient

You create the KinesisVideoClient object by calling the createKinesisVideoClient operation.

mKinesisVideoClient = KinesisVideoAndroidClientFactory.createKinesisVideoClient( getActivity(), KinesisVideoDemoApp.KINESIS_VIDEO_REGION, KinesisVideoDemoApp.getCredentialsProvider());

For KinesisVideoClient to make network calls, it needs credentials to authenticate. You pass in an instance of AWSCredentialsProvider, which reads your Amazon Cognito credentials from the awsconfiguration.json file that you modified in the previous section.

Create an instance of MediaSource

To send bytes to your Kinesis video stream, you must produce the data. Amazon Kinesis Video Streams provides the MediaSource interface, which represents the data source.

For example, the Kinesis Video Streams Android library provides the AndroidCameraMediaSource implementation of the MediaSource interface. This class reads data from one of the device's cameras.

In the following code example (from the fragment/StreamConfigurationFragment.java file), the configuration for the media source is created:

private AndroidCameraMediaSourceConfiguration getCurrentConfiguration() { return new AndroidCameraMediaSourceConfiguration( AndroidCameraMediaSourceConfiguration.builder() .withCameraId(mCamerasDropdown.getSelectedItem().getCameraId()) .withEncodingMimeType(mMimeTypeDropdown.getSelectedItem().getMimeType()) .withHorizontalResolution(mResolutionDropdown.getSelectedItem().getWidth()) .withVerticalResolution(mResolutionDropdown.getSelectedItem().getHeight()) .withCameraFacing(mCamerasDropdown.getSelectedItem().getCameraFacing()) .withIsEncoderHardwareAccelerated( mCamerasDropdown.getSelectedItem().isEndcoderHardwareAccelerated()) .withFrameRate(FRAMERATE_20) .withRetentionPeriodInHours(RETENTION_PERIOD_48_HOURS) .withEncodingBitRate(BITRATE_384_KBPS) .withCameraOrientation(-mCamerasDropdown.getSelectedItem().getCameraOrientation()) .withNalAdaptationFlags(StreamInfo.NalAdaptationFlags.NAL_ADAPTATION_ANNEXB_CPD_AND_FRAME_NALS) .withIsAbsoluteTimecode(false)); }

In the following code example (from the fragment/StreamingFragment.java file), the media source is created:

mCameraMediaSource = (AndroidCameraMediaSource) mKinesisVideoClient .createMediaSource(mStreamName, mConfiguration);

Start the media source

Start the media source so that it can begin generating data and sending it to the client. The following code example is from the fragment/StreamingFragment.java file:

mCameraMediaSource.start();

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.