如何在ExoPlayer2上设置字幕? 我试过这个 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);
但是我得到了这个错误:
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 ...
关于Android - ExoPlayer2 字幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39798846/