My Activity :
`
Format subtitleFormat = Format.createTextSampleFormat(null,MimeTypes.TEXT_VTT,"en");
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "exoplayer2example"));
MediaSource subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse("https://www.iandevlin.com/html5test/webvtt/upc-video-subtitles-en.vtt"), subtitleFormat, C.TIME_UNSET);
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"));
MergingMediaSource mergedSource = new MergingMediaSource(videoSource, subtitleSource);
exoPlayer = ExoPlayerFactory.newSimpleInstance(this);
TextureView playerSub = (TextureView) findViewById(R.id.sv_sub);
exoPlayer.setVideoTextureView(playerSub);`
My Layout :
`
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/player_frame_layout">
<TextureView
android:id="@+id/sv_sub"
android:layout_width="298dp"
android:layout_height="205dp"
android:visibility="visible" />
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/player_main"
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>`
i'cant display subtitle, where have I made a mistake?
The setVideoTextureView method sets a view for the video part of the media only. To get subtitles you need to register a text output by calling setTextOutput. You can choose to implement TextOutput directly, in which case you'll have to take care of rendering the subtitles yourself. Alternatively, the library provides SubtitleView, which implements TextOutput and will do the rendering for you. You may also like to look at PlayerView, which takes care of video and subtitle rendering, as well as providing player controls.
As an aside, you probably also need to enable the subtitle track for it to be output, or (probably easier) use the C. SELECTION_FLAG_DEFAULT selection flag when creating the Format, so that it's enabled by default.
Most helpful comment
The
setVideoTextureViewmethod sets a view for the video part of the media only. To get subtitles you need to register a text output by callingsetTextOutput. You can choose to implementTextOutputdirectly, in which case you'll have to take care of rendering the subtitles yourself. Alternatively, the library provides SubtitleView, which implementsTextOutputand will do the rendering for you. You may also like to look atPlayerView, which takes care of video and subtitle rendering, as well as providing player controls.As an aside, you probably also need to enable the subtitle track for it to be output, or (probably easier) use the
C. SELECTION_FLAG_DEFAULTselection flag when creating theFormat, so that it's enabled by default.