How do I tell if a playlist is a music playlist in c#?
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 s开发者_如何学Ctring[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 :)
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
精彩评论