'Java UTF8 encoding Subtitles Content

I take subtitle from URL and display it in exoplayer, but the subtitle content is full of symbols because the language of the text is Arabic, Greek, Chinese, etc. How do I encode MediaScource to UTF8 before displaying it in the video?

Here is my code to prepare the content of the subtitles:

MediaSource subtitleSource = 
    new SingleSampleMediaSource
            .Factory(dataSourceFactory)
            .createMediaSource(
                Uri.parse(subtitlesUrl), 
                subtitleFormat, 
                C.TIME_UNSET
            )
;

With this code it loads the subtitles correctly but only in English.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source