I just found out about the Windows Media Player library for C#, since I am making a stupid little app for my friend I thought that I would add it in (since he loves music).
string ply = "Playlist";
WMPLib.IWMPPlaylist pls;
WMPLib.IWMPPlaylistArray plItems;
plItems = axWindowsMediaPlayer1.playlistCollection.getByName(ply);
if (plItems.count == 0)
{
pls = axWindowsMediaPlayer1.playlistCollection.newPlaylist(ply);
}
else
{
plItems.Item(0);
string line;
System.IO.StreamReader stream = new StreamReader(pth);
while ((line = stream.ReadLine()) != null)
{
if (File.Exists(line))
{
WMPLib.IWMPMedia m1 = axWindowsMediaPlayer1.newMedia(line);
pls.appendItem(m1); /*gives an error here (use of unassigned variable)*/
}
}
}
}
I've tried creating an instance of the playlist, but I can't get it to allow that line, any help would be appreciated (Note that the 'pth' string was declare earlier in the method
The problem is that if
plItems.count
is greater than 0, thenpls
is never set to anything, so you can't callappendItem
on it.Perhaps you meant to say
instead of
(which doesn't do anything) in your
else
branch. This will cause your app to add media items to the first playlist in the library.