Wednesday, April 07, 2010

WMV C# Meta Information Update Example

I have recently downloaded all the www.dimecasts.net Videos, I then tried to play them on my Xbox, but they weren't in order, so made it quite hard to follow. I therefore created an App to edit the WMV titles, which the Xbox reads.

This code is "ok", I should really make the code into a wrapper library, but this is just a bit of a proof of concept really.

Firstly, you need to add the WMP.dll to the form using the Toolbox, which should appear as the Windows Media Player Control, it will then add two references

AxWMPLib
WMPLib

Then the main code for getting the Meta Data is



private string GetTitle(string filePath)
{
var mediaPlayer = new WindowsMediaPlayerClass();

IWMPMedia mediaItem = mediaPlayer.add(filePath);

return mediaItem.getItemInfo("Title");

}



I got all the attribute names running code like this



for (int i=0; i<mediaitem.attributeCount; i++) {
Console.WriteLine(mediaitem.getAttributeName(i) + " = " + mediaitem.getItemInfo(mediaitem.getAttributeName(i)) );
}



The code for setting it also very simple




private void SetTitle(string filePath, string title)
{
var mediaPlayer = new WindowsMediaPlayerClass();

IWMPMedia mediaItem = mediaPlayer.add(filePath);


mediaItem.setItemInfo("Title", title);
}




Here is the source code:
http://sarkie.webhop.org/Files/WindowsMediaEditor.zip

0 comments:

Post a Comment