Exoplayer: Display Subtitle on TextureView

Created on 13 Dec 2018  路  1Comment  路  Source: google/ExoPlayer

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:orientation="vertical" android:layout_width="match_parent"
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?

question

Most helpful comment

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

noamtamim picture noamtamim  路  3Comments

mkaflowski picture mkaflowski  路  3Comments

Ufosek picture Ufosek  路  3Comments

orcunkobal picture orcunkobal  路  3Comments

R00We picture R00We  路  3Comments