How to set subtitles on ExoPlayer2? I have tried this tu bild MergingMediaSource:
SingleSampleMediaSource singleSampleSource = new SingleSampleMediaSource(Uri.fromFile(new File("/sdcard/Download/a.vtt")), mediaDataSourceFactory,
Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT, null, Format.NO_VALUE, C.SELECTION_FLAG_DEFAULT, "se", null, 0),
50000 //in us
);
return new MergingMediaSource(new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
mainHandler, eventLogger), singleSampleSource);
but I got this error:
Unexpected exception loading stream
java.lang.NullPointerException: Attempt to get length of null array
at com.google.android.exoplayer2.source.SingleSampleMediaPeriod$SourceLoadable.load(SingleSampleMediaPeriod.java:272)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:295)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Format textFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP,
null, Format.NO_VALUE, Format.NO_VALUE, "ar", null);
MediaSource subtitleSource = new SingleSampleMediaSource("link srt url",
mediaDataSourceFactory, textFormat, C.TIME_UNSET);
MergingMediaSource mergedSource = new MergingMediaSource(mediaSource, subtitleSource);
more...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With