【问题标题】:MediaInfo get subtitles more sensiblyMediaInfo 更明智地获取字幕
【发布时间】:2022-01-16 20:37:42
【问题描述】:

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

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

Input string was not in a correct format

那么我怎样才能获得字幕并在字符串或数组中很好地列出它们,就像这样:Eng、Fra、Spa 没有硬代码和以上错误。 (如果没有潜艇,我每次都会收到这个错误)。

我的代码:

// 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";

【问题讨论】:

    标签: c# arrays iteration mediainfo


    【解决方案1】:

    以下代码未经测试或编译。只是一个想法,你可以如何根据你的代码做到这一点。

    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") + ",";
    }
    

    【讨论】:

    • 谢谢!这行得通!
    猜你喜欢
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    • 1970-01-01
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    相关资源
    最近更新 更多