MediaInfo 更明智地获取字幕

MediaInfo get subtitles more sensibly

我使用 MediaInfo Wrapper 制作 windows 表单应用程序,但我找不到任何好的解决方案来获取所有字幕并将它们放入数组或字符串中。

因为如果我硬编码 subtitle1, subtitle2, subtitle3, subtitle4 等等...根本没有字幕或者我硬编码了那么多,我得到了错误:

Input string was not in a correct format

那么我如何获得字幕并将它们很好地列在字符串或数组中,如下所示:EngFraSpa 没有硬代码和以上错误。 (如果没有潜艇,我每次都会收到这个错误)。

我的代码:

// Hardcoding (possible) subtitles...
string subOne = MI.Get(StreamKind.Text, 0, "Language/String3");
string subTwo = MI.Get(StreamKind.Text, 1, "Language/String3");
string subThree = MI.Get(StreamKind.Text, 2, "Language/String3");

string subtitlesCount = MI.Get(StreamKind.General, 0, "TextCount"); // Count how many subtitles included

string subtitles = "";

int subtitlesInt = Int32.Parse(subtitlesCount);

// Trying to find better solution over here...
if (subtitlesInt >= 1 && subtitlesInt < 2)
{
   subtitles = subOne;
} else if (subtitlesInt >= 1 && subtitlesInt <= 2)
{
   subtitles = subOne + "," + subTwo;
} else {
   subtitles = "";
}

 //var subsArray = subtitles.Split(',');
 //subtitles = String.Join(",", subsArray);

 // Display mediainfo data to textbox
 string data = "";

 data += "Subtitles: " + subtitles + "\r\n";

以下代码未经测试或编译。只是想知道如何根据您的代码执行此操作。

string subtitles = "";
int subtitlesInt = Int32.Parse(MI.Get(StreamKind.General, 0, "TextCount"));

for(int i = 0, i < subtitlesInt; i++)
{
    subtitles += MI.Get(StreamKind.Text, i, "Language/String3") + ",";
}