在 C# 中如何判断播放列表是否是音乐播放列表?

发布于 2024-10-22 02:40:33 字数 638 浏览 6 评论 0原文

到目前为止,我已经附加了我的代码,我的问题是所有播放列表都为其类型返回“auto”或“wpl”。 (这全部使用 WMPLib 参考)

mediaplayer = new WindowsMediaPlayer();
// Init. Playlists
IWMPPlaylistCollection plcollection = mediaplayer.playlistCollection;
plarray = plcollection.getAll();
int i = 0, count = plarray.count;
string[] t = new string[count];

// Here is where I want to sort out non-music playlists
// And add them to the ListBox
for (i = 0; i < count - 1; i++)
   t[i] = plarray.Item(i).getItemInfo("PlaylistType");

for (i = 0; i < count; i++ )
   PlaylistBox.Items.Add("" + plarray.Item(i).name);

不相关,但如果您知道如何将播放列表附加为数据而不是字符串,那也会很有帮助:)

I've attached my code so far, my problem is all the playlists return "auto" or "wpl" for their type. (This is all using a WMPLib reference)

mediaplayer = new WindowsMediaPlayer();
// Init. Playlists
IWMPPlaylistCollection plcollection = mediaplayer.playlistCollection;
plarray = plcollection.getAll();
int i = 0, count = plarray.count;
string[] t = new string[count];

// Here is where I want to sort out non-music playlists
// And add them to the ListBox
for (i = 0; i < count - 1; i++)
   t[i] = plarray.Item(i).getItemInfo("PlaylistType");

for (i = 0; i < count; i++ )
   PlaylistBox.Items.Add("" + plarray.Item(i).name);

Unrelated, but if you know how to attach the playlists as data instead of strings that would be helpful too :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二智少女 2024-10-29 02:40:33

我想您可以迭代播放列表项目,如果项目的“MediaType”属性等于“音频”,则认为此列表包含音频文件。像这样:

private bool ListHasAudio(IWMPPlaylist playList)
{
    if (playList != null && playList.count > 0)
    {
        for (int n = 0; n < playList.count; n++)
        {
            IWMPMedia media = playList.get_Item(n);
            string mediaType = media.getItemInfo("MediaType");
            if (mediaType != null && mediaType.Equals("audio", StringComparison.CurrentCultureIgnoreCase))
                return true;
        }
    }
    return false;
}

这是你如何使用它:

var mediaplayer = new WindowsMediaPlayer();
// Init. Playlists
IWMPPlaylistCollection plcollection = mediaplayer.playlistCollection;
var plarray = plcollection.getAll();
// Load list box items
for (int i = 0; i < plarray.count; i++)
{
    IWMPPlaylist playList = plarray.Item(i);
    if (ListHasAudio(playList))
        PlaylistBox.Items.Add(playList.name);
}

希望这有帮助,问候

I guess you can iterate through playlist items and if item's "MediaType" attribute equals "audio" deem this list as the one containing audio files. Smth like this:

private bool ListHasAudio(IWMPPlaylist playList)
{
    if (playList != null && playList.count > 0)
    {
        for (int n = 0; n < playList.count; n++)
        {
            IWMPMedia media = playList.get_Item(n);
            string mediaType = media.getItemInfo("MediaType");
            if (mediaType != null && mediaType.Equals("audio", StringComparison.CurrentCultureIgnoreCase))
                return true;
        }
    }
    return false;
}

here's how you can use it:

var mediaplayer = new WindowsMediaPlayer();
// Init. Playlists
IWMPPlaylistCollection plcollection = mediaplayer.playlistCollection;
var plarray = plcollection.getAll();
// Load list box items
for (int i = 0; i < plarray.count; i++)
{
    IWMPPlaylist playList = plarray.Item(i);
    if (ListHasAudio(playList))
        PlaylistBox.Items.Add(playList.name);
}

hope this helps, regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文