Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android exoplayer 2.7.3中未显示字幕_Android_Android Studio_Exoplayer_Exoplayer2.x - Fatal编程技术网

Android exoplayer 2.7.3中未显示字幕

Android exoplayer 2.7.3中未显示字幕,android,android-studio,exoplayer,exoplayer2.x,Android,Android Studio,Exoplayer,Exoplayer2.x,我使用exoplayer从外部url播放mkv视频。 视频很恐怖,我尝试添加自己的字幕(.vtt),但字幕没有显示。 仅显示视频中的原始字幕。如何将视频中的原始字幕切换为自己的字幕?如果我播放mkv视频时没有原始sub,则显示我自己的sub。但如果我播放原始sub的视频,则无法显示我自己的sub。这是我的密码 public void setSelectedSubtitle(MediaSource mediaSource, String subtitle, Context context) {

我使用exoplayer从外部url播放mkv视频。 视频很恐怖,我尝试添加自己的字幕(.vtt),但字幕没有显示。 仅显示视频中的原始字幕。如何将视频中的原始字幕切换为自己的字幕?如果我播放mkv视频时没有原始sub,则显示我自己的sub。但如果我播放原始sub的视频,则无法显示我自己的sub。这是我的密码

public void setSelectedSubtitle(MediaSource mediaSource, String subtitle, Context context) {
    MergingMediaSource mergedSource;
    if (subtitle != null) {
        Uri subtitleUri = Uri.parse(subtitle);

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

        DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(context,
                Util.getUserAgent(context, CLASS_NAME), new DefaultBandwidthMeter());


        MediaSource subtitleSource = new SingleSampleMediaSource
                .Factory(dataSourceFactory)
                .createMediaSource(subtitleUri, subtitleFormat, C.TIME_UNSET);

        mergedSource = new MergingMediaSource(mediaSource, subtitleSource);
        player.prepare(mergedSource, false, false);
        player.setPlayWhenReady(true);
        //resumePlayer();

    } else {
        Toast.makeText(context, "there is no subtitle", Toast.LENGTH_SHORT).show();
    }

你们怎么打开字幕?