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:
-
Get a reference to the Video Cloud OfflineCatalog client.
private OfflineCatalog catalog; ... catalog = new OfflineCatalog(this, eventEmitter, ACCOUNT_ID, POLICY_KEY); ...
-
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.
OfflineCatalog.getMediaFormatTracksAvailable( @NonNull final Video video, @NonNull final MediaDownloadable.MediaFormatListener mediaFormatListener)
-
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:
- MediaDownloadable.VIDEO_RENDITIONS - Contains an array list of
MediaFormat
objects - MediaDownloadable.AUDIO_LANGUAGES - Contains an array list of
MediaFormat
objects. - MediaDownloadable.AUDIO_LANGUAGE_ROLES - Contains an array list of strings. This list provides additional information with respect to the
MediaDownloadable.AUDIO_LANGUAGES
. The indices match the audio languages list. Example of audio roles can be main and alternative. - MediaDownloadable.CAPTIONS - Contains an array list of
MediaFormat
objects
- MediaDownloadable.VIDEO_RENDITIONS - Contains an array list of
-
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);
-
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();
-
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<>(); newCaptions.add(captions.get(0)); filteredBundle.putParcelableArrayList(MediaDownloadable.CAPTIONS, newCaptions); }
-
Set the
filteredBundle
to theMediaDownloadable
object.mediaDownloadable.setConfigurationBundle(filteredBundle);
-
Download the video.
offlineCatalog.downloadVideo(video);
Internally, the
OfflineCatalog
will use the cachedMediaDownloadable
provided by theMediaDownloadable.MediaFormatListener
callback.
Code sample
For a complete example of downloading additional audio tracks and captions files, see the Offline Playback sample app.