Introduction
I had an issue where iTunes so graciously renamed all of my music files to a four character file name. This was fine for the MP3s because Windows shell displays the song name, but what about M4As? I had no idea what the songs were. So, I set out to find a way to rename each song and copy it to a file share. The MP3s were easy. I searched high and low for ideas about the M4As. Then, after hours of searching, I got that ever golden gem of info that set me on the right path. "Add the QuickTime Control Library to your Visual Studio Project", a person said somewhere deep in a forum. Ah ha!! Why didn't I think of that?! But it wasn't quite that simple.
Let me try to shed some light.
Background (What didn't work)
I first added the QTControl.dll reference to my project and created an instance like so...
QTControl m_qtCtrl = new QTControl();
m_qtCtrl.URL = filePath;
So now, the control has a handle on the file and we should be able to pull info from the file using the control's Movie object. Movie is basically whatever file you pass to the URL, which by the way can be a URL or a file path. Movie can be JPG, M4A, Mov, or whatever else QuickTime can read.
QTOLibrary.QTMovie mov = new QTOLibrary.QTMovie();
You can try this all day long, and mov
will be null
!!! Which is very frustrating for someone like me who is learning computer programming. So, let's move on to what I finally figured out.
Using the code (What worked for me)
It seems that to use the QTControlLib, you have to host the control in a form.
- First, add QTOControl.dll to your ToolBox in Visual Studio.
- Then, drag the control onto you from. I then set its
Visible
property to false because I don't need a video player. But this was good to know as well for future projects.
- Doing this creates a new control hosted on your form, named
axQTControl1
. Go back to you form's code and pass the file path.
axQTControl.URL = filePath;
Now, when you create an instance of this control's movie object, it will not be null
!!
QTOLibrary.QTMovie mov = new QTOLibrary.QTMovie();
mov = axQTControl1.Movie;
mov
has all the info you would expect it to have!! I grabbed its info like this and ran with it:
string artistName = mov.get_Annotation((int)QTAnnotationsEnum.qtAnnotationArtist);
string albumName = mov.get_Annotation((int)QTAnnotationsEnum.qtAnnotationAlbum);
string songTitle = mov.get_Annotation((int)QTAnnotationsEnum.qtAnnotationFullName);
That's it!
Points of interest
The source code is more or less for example. This is also my first C# project. Yay!! I've been doing VB.NET for about a year. So give me a break when voting.
As I started to explain in the introduction, my intent was to get the artist's name and the song name and copy it to some folder (file-share\Music\artistName\songName.m4a). I ran this on about 2700 M4A files and about 3000 MP3s. It took about an hour total. Most of the project's code for the MP3s was from another very helpful CodeProject article.
The code in Form1
is quite messy, but there aren't very many lines, so I think you can make sense out of it. It is set to process M4As right now. To process MP3s, change M4AFileSearch(sDir);
to MP3FileSearch(sDir);
at line 62.
History
There is no history, but I would like to expand this project if there is a need to.