ExoPlayer - 古怪的阿拉伯语/波斯语字幕格式

时间:2018-02-20 19:08:50

标签: android arabic exoplayer subtitle arabic-support

我正在尝试制作带字幕的视频播放器。除了一件事,一切都已设置并正常工作。我的阿拉伯语字幕没有显示正确的字样。他们看起来很奇怪的符号和东西..这样的东西:

enter image description here

这是我的ExoPlayer设置与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);

有什么解决办法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

该文件的编码为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(); 。您应该先将其更改为Unicode,然后才能正确看到它。

<uses-permission android:name="android.permission.INTRNET"/>