简体   繁体   English

使用vlcj(Java)验证字幕文件

[英]Validate subtitles file using vlcj (Java)

I am using an instance of vlcj DefaultEmbeddedMediaPlayer to play video. 我正在使用vlcj DefaultEmbeddedMediaPlayer的实例播放视频。 When adding subtitles to the video I want to see if the subtitle file is valid, and throw an Exception if it is not. 将字幕添加到视频时,我想查看字幕文件是否有效,如果不是,则抛出Exception。 This is my code: 这是我的代码:

File subtitlesFile = new File("subs.srt");
player.setSubTitleFile(subTitleFile);

The method setSubTitleFile(File subTitleFile) doesn't have a return value, but looking into its implementation I can see that it passes the call to libvlc, calling libvlc_video_subtitle_file(libvlc_media_player_t p_mi, String psz_subtitle) , which returns 1 or 0 depending on if the subtitles have been added successfully or not. setSubTitleFile(File subTitleFile)方法没有返回值,但是查看它的实现,我可以看到它将调用传递给libvlc,调用了libvlc_video_subtitle_file(libvlc_media_player_t p_mi, String psz_subtitle) ,它返回1还是0具体取决于字幕添加成功与否。 So I inherited from DefaultEmbeddedMediaPlayer and wrote my own version of that method: 因此,我继承了DefaultEmbeddedMediaPlayer并编写了该方法的自己的版本:

public void setSubTitleFile(String subTitleFileName) {
    final int status = libvlc.libvlc_video_set_subtitle_file(mediaPlayerInstance(), subTitleFileName);
    System.out.println(status);
    // throw Exception if status is false
}

Surprisingly this always gives me status 1 , which means success. 令人惊讶的是,这始终使我的状态为1 ,这意味着成功。 Even if I am passing an empty text file. 即使我传递的是空文本文件。 Is this a bug? 这是错误吗? I really do not want to parse the subtitle file manually beforehand. 我真的不想事先手动解析字幕文件。 Using the native VLC Player, I am getting an error as expected if the subtitles are invalid. 使用本机VLC播放器,如果字幕无效,则会出现预期的错误。 Anything I could do here? 我在这里能做什么?

EDIT: This is a screenshot from the native VLC player when adding an empty SRT file during play. 编辑:这是从本地VLC播放器截取的屏幕截图,在播放过程中添加了空的SRT文件。 VLC subtitles file error VLC字幕文件错误

As far as I know, LibVLC/VLC is not parsing the subtitle file when you call libvlc_video_set_subtitle_file. 据我所知,当您调用libvlc_video_set_subtitle_file时,LibVLC / VLC不会解析字幕文件。 All it is basically doing is setting a string value on some native structure that will be used later. 它基本上要做的就是在某些本机结构上设置一个字符串值,稍后将使用它。 So, you get a status of "success" because that call did its job of setting that string value. 因此,您将获得“成功”状态,因为该调用完成了设置该字符串值的工作。

Therefore, you will only know if the subtitle file is valid when VLC starts playing your media and it attempts to load the file at that point. 因此,您仅在VLC开始播放媒体并尝试加载该文件时才知道字幕文件是否有效。 Even then, I do not think you will get a specific error message - there will simply be an absence of a subtitle track. 即使那样,我认为您也不会收到特定的错误消息-只会缺少字幕轨道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM