This topic describes how to configure a subtitle track to be displayed for video playback.
Samsung Smart TVs support subtitles for video playback. Subtitle tracks can be embedded in the media file, or stored in an external subtitle file.
The AVPlay API supports internal and external subtitles in the following common formats:
To configure the subtitle file path:
Downloading the subtitle file to the "wgt-private-tmp" virtual root (the application's private volatile storage) is recommended.
AVPlay
setExternalSubtitlePath()
... var downloadRequest = new tizen.DownloadRequest(yourSubtitleURL, "wgt-private-tmp"); ... tizen.download.start(downloadRequest, { oncompleted: function(downloadId, fullPath) { console.log('absolute path of downloaded file : '+fullPath); // call setExternalSubtitlePath() before prepare() webapis.avplay.setExternalSubtitlePath(fullPath); ... webapis.avplay.prepare(); }, onfailed: function(error) { console.log('Failed to download Subtitle'); } });
Whenever the subtitle text changes during media playback, the onsubtitlechange() callback is called, returning the subtitle data value.
onsubtitlechange()
If there are multiple subtitle tracks (such as for different languages), you can switch tracks during media playback.
To select a subtitle track:
getTotalTrackInfo()
type
TEXT
index
extra_info
var totalTrackInfo = webapis.avplay.getTotalTrackInfo(); for(var i=0; i<totalTrackInfo.length;i++) { if(totalTrackInfo.type =='TEXT') { console.log('Find subtitle track.'); console.log('subtitle track index is' + totalTrackInfo.index); console.log('subtitle track language is' + totalTrackInfo.extra_info.track_lang); } }
setSelectTrack()
// Select subtitle track with index 2 webapis.avplay.setSelectTrack('TEXT',2);
If the subtitles are not synchronized with the video during playback, you can adjust the synchronization using a time delay.
To adjust the subtitle delay, call setSubtitlePosition() with the delay duration in milliseconds as the parameter. The duration can be a positive or negative number; a positive delay displays the subtitles later, while a negative delay displays the subtitles sooner.
setSubtitlePosition()
// Display the subtitles with a 5000 ms delay webapis.avplay.setSubtitlePosition(5000);