2

I'm trying to create a video player with subtitles. everything is set up and working correctly , except one thing. my Arabic subtitles are not showing correctly as they should be. they look so weird with symbols and stuff.. something like this :

enter image description here

Here's my ExoPlayer Setup with subtiltes :

Uri srt = Uri.parse("http://download1651.mediafire.com/titdvyxje25g/j5wpodffdhn005r/Thor+3+.WEB+%28NoColored%29.srt");
    
    Handler mainHandler = new Handler();
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector =
            new DefaultTrackSelector(videoTrackSelectionFactory);
    player =
            ExoPlayerFactory.newSimpleInstance(this, trackSelector);
    DefaultBandwidthMeter bandwidthMeter2 = new DefaultBandwidthMeter();
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
            Util.getUserAgent(this, "yourApplicationName"), bandwidthMeter2);
    Format textFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP,
            null, Format.NO_VALUE, Format.NO_VALUE, "ar", null, Format.OFFSET_SAMPLE_RELATIVE);
    MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
            .createMediaSource(Uri.parse(getVideoUri()));
    MediaSource textMediaSource = new SingleSampleMediaSource.Factory(dataSourceFactory)
            .createMediaSource(srt, textFormat, C.TIME_UNSET);
    MediaSource mediaSource = new MergingMediaSource(videoSource, textMediaSource);


    player.prepare(mediaSource);

is there any solution on how to fix that ?

mahdi
  • 396
  • 3
  • 14
Tamim Attafi
  • 1,732
  • 2
  • 14
  • 30

1 Answers1

1

The encoding of that file is windows-1256. you should change it to Unicode first and then you can see it correctly.

BufferedReader reader = new BufferedReader(
        new InputStreamReader(new FileInputStream("arabic sub.srt"), "windows-1256")
    );
String line = null;
BufferedWriter writer = new BufferedWriter(
    new OutputStreamWriter(new FileOutputStream("new.srt"), "UTF-8")
);
while((line = reader.readLine())!= null){        
    writer.write(line);
    writer.write("\r\n");
}
writer.close();
VahidN
  • 17,268
  • 7
  • 68
  • 112
  • So these lines of code are going to recreate the .srt in UTF-8? My .srt is loaded directly from the web.. Do u think that it will work? U can look above on my code that I'm using a Uri.. Please can provide me with more explanation ? Thank you – Tamim Attafi Feb 21 '18 at 04:16
  • You can download the file, change its encoding using the mentioned code and then convert its local path to Uri this way: `new File(path).toURI().toURL();` – VahidN Feb 21 '18 at 07:18
  • thank you, I've just converted my .srt before uploading them. i think that would be easier cause i have to edit them too. – Tamim Attafi Feb 25 '18 at 17:59