使用为Android编译的LibVLC显示MPEG2流中的DVB字幕

时间:2018-09-24 12:43:33

标签: android vlc libvlc subtitle vlc-android

使用以下代码,我能够播放具有3条音轨(视频,音频和dvb字幕)的udp流(mpeg2 ts),但是我试图检索字幕音轨并显示它,但我无法找到有关该操作的任何清晰文档。

   // Create LibVLC
ArrayList<String> options = new ArrayList<String>();
        options.add("-vvv"); // verbosity
        options.add("--autoscale");

libvlc = new LibVLC(this, options);
        holder.setKeepScreenOn(true);

// Creating media player
mMediaPlayer = new MediaPlayer(libvlc);
        mMediaPlayer.setAspectRatio("16:9");
        mMediaPlayer.setEventListener(mPlayerListener);


// Seting up video output
final IVLCVout vout = mMediaPlayer.getVLCVout();
        vout.setVideoView(mSurface);

        if (mSubtitlesSurface != null)
        vout.setSubtitlesView(mSubtitlesSurface);
        vout.setWindowSize(1920,1080);
        vout.addCallback(this);
        vout.attachViews();
    Media m = new Media(libvlc, Uri.parse(media));
    mMediaPlayer.setMedia(m);
    mMediaPlayer.play();

我正在尝试使用mMediaPlayer.getMedia().getTrackCount()mMediaPlayer.getSpuTracksCount()在所有情况下都返回零;甚至不包括基本的音频和视频轨道。

对此有任何帮助吗?

注意:我从[https://wiki.videolan.org/AndroidCompile/]编译了LibVLC,并将.aar存档保存到我的项目中。

2 个答案:

答案 0 :(得分:1)

您可能需要先呼叫media.parse(),以便能够发现spu音轨,然后再设置一个。

答案 1 :(得分:0)

添加到选项的参数将有助于显示字幕:

// Create LibVLC
    ArrayList<String> options = new ArrayList<String>();
    options.add("-vvv"); // verbosity
    options.add("--autoscale");
    args.add("--sub-track=0");//this option is used to show the first subtitle track
    libvlc = new LibVLC(this, options);
    holder.setKeepScreenOn(true);

    // Creating media player
    mMediaPlayer = new MediaPlayer(libvlc);
    mMediaPlayer.setAspectRatio("16:9");
    mMediaPlayer.setEventListener(mPlayerListener);


    // Seting up video output
    final IVLCVout vout = mMediaPlayer.getVLCVout();
    vout.setVideoView(mSurface);

    if (mSubtitlesSurface != null)
        vout.setSubtitlesView(mSubtitlesSurface);
    vout.setWindowSize(1920,1080);
    vout.addCallback(this);
    vout.attachViews();
    Media m = new Media(libvlc, Uri.parse(media));
    mMediaPlayer.setMedia(m);
    mMediaPlayer.play();