Exoplayer HLS不显示字幕

时间:2018-06-29 08:09:37

标签: android exoplayer

我正在开发流式应用程序。我为此目的使用了exoplayer2。我正在使用HLS流协议。流视频时,我需要显示字幕。除字幕外,其他一切都进行顺利。我的播放器未显示示例字幕。 我的代码如下:

        uri = Uri.parse(url);
    videoSource = new HlsMediaSource.Factory(DATA_SOURCE_FACTORY).createMediaSource(uri);
    Uri uri1 = Uri.parse("https://bitdash-a.akamaihd.net/content/sintel/hls/subtitles_en.vtt");

    Format subtitleFormat = Format.createTextSampleFormat(
            null, // An identifier for the track. May be null.
            MimeTypes.APPLICATION_SUBRIP, // The mime type. Must be set correctly.
            Format.NO_VALUE, // Selection flags for the track.
            "en");

    DefaultBandwidthMeter bandwidthMeter2 = new DefaultBandwidthMeter();
     DefaultDataSourceFactory dataSourceFactory =  new DefaultDataSourceFactory(this,
            Util.getUserAgent(this, "ExoCastDemoPlayer"), bandwidthMeter2);
    subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(uri1,subtitleFormat, C.TIME_UNSET);
    MergingMediaSource mergedSource = new MergingMediaSource(videoSource, subtitleSource);
    player.prepare(mergedSource);
    player.seekTo(currentPosition);
    player.setPlayWhenReady(true);
    player.addListener(new IPlayerEventListener(this));
    dropdown = findViewById(R.id.exo_resolution);
    adapter = new SpinnerAdapter(this, items);
    dropdown.setAdapter(adapter);
    dropdown.setOnItemSelectedListener(new SpinnerOnItemSelectedListener());

我按照exoplayer的开发人员指南显示了字幕,但没有任何内容。 提前致谢。

0 个答案:

没有答案