Multiple Audio Tracks for Offline Playback with the Native SDK for Android

In this topic, you will learn how to return multiple audio and text tracks when working with Offline Playback with the Brightcove Native Player SDK for Android.

Manage multiple tracks

By default, no captions files and only one audio track is downloaded. To download additional assets associated with the video, follow these steps:

  1. Get a reference to the Video Cloud OfflineCatalog client.

    private OfflineCatalog catalog;
    catalog = new OfflineCatalog(this, eventEmitter, ACCOUNT_ID, POLICY_KEY);
  2. Call the getMediaFormatTracksAvailable method, passing in the Video object for which you want to get information about, and the MediaFormatListener to listen for the returned data.

      @NonNull final Video video,
      @NonNull final MediaDownloadable.MediaFormatListener mediaFormatListener)
  3. The MediaFormatListener calls the following method:

    void onResult(MediaDownloadable mediaDownloadable, Bundle mediaFormatBundle);

    The MediaDownloadable object contains information, including video renditions, audio languages and captions. The mediaDownloadable object is cached, and used when you call OfflineCatalog.downloadVideo(Video).

    The Bundle object contains information about the available Media Format tracks, and has the following properties:

  4. Retrieve lists of data from the bundle. Here are examples for retrieving the different lists:

    ArrayList<MediaFormat> video = bundle.getParcelableArrayList(MediaDownloadable.VIDEO_RENDITIONS);
    ArrayList<MediaFormat> audio = bundle.getParcelableArrayList(MediaDownloadable.AUDIO_LANGUAGES);
    ArrayList<String> roles = bundle.getStringArrayList(MediaDownloadable.AUDIO_LANGUAGE_ROLES);
    ArrayList<MediaFormat> captions = bundle.getParcelableArrayList(MediaDownloadable.CAPTIONS);
  5. Create a new Bundle (filteredBundle) to select the audio tracks and closed captions that you want to include in the download.

    Bundle filteredBundle = new Bundle();
  6. Filter the tracks that you want from the list that you created earlier, and add it to the new filteredBundle.

    ArrayList<MediaFormat> captions = bundle.getParcelableArrayList(MediaDownloadable.CAPTIONS);
    if (captions != null && captions.size() > 0) {
       ArrayList<MediaFormat> newCaptions = new ArrayList<>();
    filteredBundle.putParcelableArrayList(MediaDownloadable.CAPTIONS, newCaptions);
  7. Set the filteredBundle to the MediaDownloadable object.

  8. Download the video.


    Internally, the OfflineCatalog will use the cached MediaDownloadable provided by the MediaDownloadable.MediaFormatListener callback.

Code sample

For a complete example of downloading additional audio tracks and captions files, see the Offline Playback sample app.