C# - Modify WMA extended properties programatically (possibly with NAudio)

268 views Asked by At

I need to programmatically modify the Title property of a couple hundred WMA files that I have.

I've been banging my head against the wall trying to handle this for a little while now. There are a few libraries that claim to be able to handle this, but the documentation is extremely poor. I have downloaded NAudio, and suspect there is a way there of handling what I need, but again the documentation is woefully inadequate to the task.

Does anyone have any insight to how to modify the extended properties of an existing WMA file?

1

There are 1 answers

0
Matt On BEST ANSWER

I found a project on sourceforge that got me to the point of being able to modify the title property as needed.

The project is located here: http://professionaltag.sourceforge.net/

The source code example is a solution with multiple projects. For me, I ended up not making use the UI the author provided, and rolled my own around the appropriate classes. What I needed was in the "Tag" project, specifically the Tags.ASF.ASFTagInfo class. The class can either be used as-is, or dissected if necessary. I used it without modification.

I offer below the method I use to modify the track info. For my purposes, I only want to modify the track name if the last 2 characters of the file name are digits, but the concept is the same for whatever changes you want to make.

    private void ModifyTrackInfo(string PathToWMA)
    {
        // "Last()" is an extension method on string defined elsewhere in project
        //      it simply get the to get the specified number of trailing characters of a string 
        string last2String = System.IO.Path.GetFileNameWithoutExtension(PathToWMA).Last(2);

        int last2Int;
        if (int.TryParse(last2String, out last2Int))
        {
            Tags.ASF.ASFTagInfo tagInfo = new Tags.ASF.ASFTagInfo(PathToWMA, true);                
            tagInfo.ContentDescription.Title =  string.Format("Track {0}", last2String);                
            tagInfo.Save();
        }            
    }