Skip to main content
Skip table of contents

Subtitles

To test this feature and view the example code, please see the (5.33.x) Android SDK 5 Example Code Quick Start guide.

Subtitles can be displayed when a stream is playing by calling methods on the OTVVideoView instance.

JAVA
OTVTrackInfo[] getOTVTrackInfo()

This returns an array of all tracks in the current stream, comprising video, audio and subtitle tracks. The following subtitle track types are supported:

  • WebVTT

  • SMPTE-TT (text)

  • EIA-608 (CC608) - all four services (CC1-CC4)

  • EIA-708 (CC708) - first service only

  • SRT

Prerequisites

A clear stream with subtitles is available for testing.

Example code

Use the following example code to enable subtitles.

Subtitle tracks are located by interrogating for tracks of type TIMEDTEXT.

JAVA
    OTVTrackInfo[] trackInfo = mOTVVideoView.getOTVTrackInfo();
    for (int i = 0; i < trackInfo.length ; i++) {
      if (trackInfo[i].getType() == OTVTrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT) {
        // Add to text track list with index 'i'
      } else if (trackInfo[i].getType() == OTVTrackInfo.MEDIA_TRACK_TYPE_AUDIO) {
        // Ignore track
      } else if (trackInfo[i].getType() == OTVTrackInfo.MEDIA_TRACK_TYPE_VIDEO) {
        // Ignore track
      }
    }
    // Return text track list and indexes to present to the user for selection

To select a track at an index of the array returned by getOTVTrackInfo().

JAVA
mOTVVideoView.selectTrack(index);

To deselect a track at an index of the array returned by getOTVTrackInfo() (optional).

JAVA
mOTVVideoView.deselectTrack(index);

To implement a listener (ITrackChangedListener) that will be called whenever the track changes (optional).

JAVA
    mOTVVideoView.registerOnTrackChangedListener(mTrackChangedListener);
    // Create a Track changed listener
    private ITrackChangedListener mTrackChangedListener = new ITrackChangedListener() {
      @Override
      public void onTrackChanged() {
        // handle anything you want to do when a stream's track changes
      }
    }

Text style

System settings control text-based subtitle appearance (size, colour, fonts, background, etc.). Typically those settings are under System > Accessibility > Captions.

External subtitles

Example for adding an external subtitle source.

JAVA
    mOTVVideoView.setVideoPath("https://path/to/video.m3u8");
    mOTVVideoView.addSubtitleSource("https://path/to/subtitles.srt", "MIME type", "Language");

Call this method immediately after setting the video path; it will return true if you have passed through a valid URI and Mime type.
If this method is called after playback has begun, it will restart playback.

This method will still return true if you pass through a valid URI that is not a subtitle address.

For details of the API calls used above, see the OTVVideoView class reference.

Accessibility settings

When using a device that has captions enabled through its Accessibility caption options, there are specific changes to the default behaviour of subtitles within the application:

  • If caption language settings are set to default language, the track within the stream marked default will be used if any are marked as such.

  • If language is not set to default, the subtitles will attempt to use a track that matches your chosen language. If a track matching the chosen language cannot be found, the default will be selected.

  • If there is no default track on the stream and default is selected, the captions manager will use the device's current language as the default track.

To override the default language selection, see (5.33.x) Provide a preferred language for audio/subtitle tracks.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.