views:

26

answers:

0

I'm relatively new to C# and want basically develop an application that works with the WMP library. According to msdn, the WMPLib offers several events dealing with the WMP library such as MediaAdded, MediaDeleted, MediaChanged, etc.

I wanted to implement to implement the event that is fired when a new media is added to the library as followed (please consider that it is only a test to see if the event handling works)

class Application
{
    static void Main(string[] args)
    {
        MediaPlayer player = new MediaPlayer();
        Form MyForm = new Form();
        Application.Run(MyForm);
    }
}

public class MediaPlayer
{
    public MediaPlayer()
    {
        WindowsMediaPlayer player = new WindowsMediaPlayer();
        player.MediaCollectionMediaAdded += new _WMPOCXEvents_MediaCollectionMediaAddedEventHandler(player_MediaCollectionMediaAdded);
    }        
    private void player_MediaCollectionMediaAdded(object pMedia)
    {
        Console.WriteLine("A new media item has been added to the library");
        IWMPMedia newItem = (IWMPMedia)pMedia;
        Console.WriteLine("Path = " + newItem.sourceURL);
    }
}

The application compiles but I unfortunately do not get the event when a media is added to the library. Does somebody know how to implement this event properly and can give me some tips?