On Tuesday i posted some code on how to removed dead tracks from windows media player. i had a lot of my workstation’s media player but never found a quick or easy of removing them. Well, here is some updated code. It does some interesting things like telling you the total play time of your songs, telling you how many songs you havent listened to yet and also total file size. So, without further ado, heres the code:<p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>

        private void Form1_Load(object sender, EventArgs e)<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /></p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>

        {</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”> </p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            WMPLib.WindowsMediaPlayer wmp = new WMPLib.WindowsMediaPlayer();</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            WMPLib.IWMPPlaylist playList = wmp.mediaCollection.getByAttribute(“MediaType”, “Audio”);</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            WMPLib.IWMPMediaCollection coll;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            coll = wmp.mediaCollection;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            System.IO.FileInfo f;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            double totalTime = 0;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            int deleted = 0;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            double totalSize = 0;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            int nonPlayedSongs = 0;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            for (int i = 0; i < playList.count; i++)</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            {</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                if (playList.get_Item(i).duration > 0)</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                {</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                    f = new System.IO.FileInfo(playList.get_Item(i).sourceURL);</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                    if (!f.Exists)</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                    {</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                        coll.remove(playList.get_Item(i), true);</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                        deleted++;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                    }</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                    else</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                    {</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                        totalTime += playList.get_Item(i).duration;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                        totalSize += f.Length;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                        if (int.Parse(playList.get_Item(i).getItemInfo(“UserPlayCount”)) == 0)</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                        {</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                            nonPlayedSongs++;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                        }</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                    }</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>                }</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            }</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            string s;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            s = TimeSpan.FromSeconds(totalTime).ToString();</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            MessageBox.Show(“Total Time: “ + s + ” Deleted: “ + deleted + ” Total size: “ + (totalSize/1024/1024) + “Mb”);</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            MessageBox.Show(nonPlayedSongs.ToString());</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            coll = null;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            wmp = null;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            playList = null;</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none”>            this.Close();</p> <p class=MsoNormal style=”MARGIN: 0cm 0cm 0pt”>        }</p>

Hopefully it displays correctly. i had to copy it out of Visual Studio, into Word and copy it back out of there. anyway, it was tested with Visual Studio 2005, and uses Media player 10. you should add the windows media player COM object to your project. there is no warrenty with this code. If you have a problem with the code, or it deletets all your songs, im sorry, but your on your own…