I have a simple application enumerating Windows Media Player playlists. It just gets name for each playlist and prints it to the console:
class Program
{
static void Main(string[] args)
{
var mediaPlayer = new WindowsMediaPlayer { uiMode = "invisible" };
var allPlaylists = mediaPlayer.playlistCollection.getAll();
Console.WriteLine("Found {0} wmp playlists");
for (int i = 0; i < allPlaylists.count; i++)
{
try
{
IWMPPlaylist wmpPlaylist = allPlaylists.Item(i); //Exception here!
Console.WriteLine("Playlist with index {0} has name '{1}'", i, wmpPlaylist.name);
}
catch (Exception e)
{
Console.WriteLine("Failed to get playlist with index {0} with error '{1}'", i, e.Message);
}
}
Console.ReadLine();
}
}
It works fine on Windows 8 but throws exception on Windows8.1 on attempt to get the playlist item from the IWMPPlaylistArray collection:
System.IO.DirectoryNotFoundException was caught HResult=-2147024893 Message=The system cannot find the path specified. (Exception from HRESULT: 0x80070003) Source=WMP_POC StackTrace: at WMPLib.IWMPPlaylistArray.Item(Int32 lIndex) at WMP_POC.Program.Main(String[] args) in InnerException:
Also it works fine for user created playlists even on Windows 8.1 but for predefined playlists like 'All Music', 'All Video' the exception is occurs.
Please, help!
I have investigated more deeply and I have found that “All Music” playlist which should reside in the “C:\Users[username]\AppData\Local\Microsoft\Media Player\Sync Playlists\en-US\00057566” is simply absent on Windows 8.1 while on Windows 8 it exists. And this is seems to be the root cause of the issue.
As I already mentioned on Windows 8.1 the problem exists only for predefined playlists and at the end of the day I have found out the following workaround which is seems to be working on the Windows 8.1. If you want to get "All Music" playlist just use the following code:
IWMPPlaylist allMusicPlaylist = mediaPlayer.mediaCollection.getByAttribute("MediaType", "Audio");
By changing "MediaType" attribute according to the table on the msdn you can get "All Video", "All Pictures" etc. predefined playlists.