Sideload字幕在埃法层中不起作用



我正在尝试用视频局限一个字幕文件,但它不起作用。

代码:

private MediaSource buildMediaSourceWithSubtitle(Uri uri, @Nullable String overrideExtension, Uri subtitle) {
    Format subtitleFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP, 0, null);
    MediaSource subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(subtitle, subtitleFormat, C.TIME_UNSET);
    MediaSource mediaSource = null;
    @ContentType int type = Util.inferContentType(uri, overrideExtension);
    switch (type) {
    case C.TYPE_DASH:
        mediaSource = new DashMediaSource.Factory(dataSourceFactory).setManifestParser(
        new FilteringManifestParser < >(new DashManifestParser(), getOfflineStreamKeys(uri))).createMediaSource(uri);
        return new MergingMediaSource(mediaSource, subtitleSource);
    case C.TYPE_SS:
        mediaSource = new SsMediaSource.Factory(dataSourceFactory).setManifestParser(
        new FilteringManifestParser < >(new SsManifestParser(), getOfflineStreamKeys(uri))).createMediaSource(uri);
        return new MergingMediaSource(mediaSource, subtitleSource);
    case C.TYPE_HLS:
        mediaSource = new HlsMediaSource.Factory(dataSourceFactory).setPlaylistParserFactory(
        new DefaultHlsPlaylistParserFactory(getOfflineStreamKeys(uri))).createMediaSource(uri);
        return new MergingMediaSource(mediaSource, subtitleSource);
    case C.TYPE_OTHER:
        mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
        return new MergingMediaSource(mediaSource, subtitleSource);
    default:
        {
            throw new IllegalStateException("Unsupported type: " + type);
        }
    }
}
mediaSource videosource = new drestrormediasource(        Viviori,        datasourceFactory,        新的DefaultExtractorsFactory(),        无效的,        无效的);格式subtitleformat =格式。        无效的,        mimetypes.application_subrip,        C.Selectionflags,        " en");MediaSource textMediasource =新的单次amplemediasource(    uri.parse(" http://www.storiesinflight.com/js_videosub/jellies.srt"),    datasourceFactory,    subtitleformat,    C.Time_unset);source = new MygingMediasource(VideoSource,textMediasource);//以后使用//嵌套到具有subtitleview作为成员的某些类类Somelistener工具...,TexTrenderer.Output,... {    ...       //此功能似乎没有被调用    公共空白(列表提示){       //在这里登录一些        如果(subtitleview!= null){        subtitleview.oncues(cues);        }    }    ...}player.setTextOutput(侦听器);...//稍后,播放视频,假设其准备好了player.setplayWhenReady(true); 

在exoplayer 2.16.1中我使用了此代码并正常工作:

val subtitle = MediaItem.SubtitleConfiguration.Builder(srtUri)
    .setMimeType(MimeTypes.APPLICATION_SUBRIP)
    .setLanguage("en")
    .setSelectionFlags(C.SELECTION_FLAG_DEFAULT)
    .build()
val mediaItem = MediaItem.Builder()
    .setUri(videoUrl)
    .setSubtitleConfigurations(ImmutableList.of(subtitle))
    .build()
player?.setMediaItem(mediaItem)

相关内容

  • 没有找到相关文章

最新更新