Need to be able to read and edit an MP3 rating in C#

I'm trying to read, and later hopefully write, the rating value on an MP3 file. I'm using the TagLibSharp library and everything I've found so far indicates that this should work but it doesn't seem to. Here's the code I'm currently using:
			TagLib.Id3v2.Tag.DefaultVersion = 3;
			TagLib.Id3v2.Tag.ForceDefaultVersion = true;
			TagLib.File mp3File =TagLib.File.Create(@"C:\Users\Russ\Downloads\Precious - copy.mp3");
			TagLib.Tag tag = mp3File.GetTag(TagLib.TagTypes.Id3v2);
			TagLib.Id3v2.PopularimeterFrame frame = TagLib.Id3v2.PopularimeterFrame.Get((TagLib.Id3v2.Tag)tag, "Windows Media Player 9 Series", true);
			// at this point, frame.Rating is always 0. Why?;

Open in new window

Here is a screenshot of the properties window of the MP3 file showing that the rating currently is set at 4 stars.
MP3 RatingI'd like to accomplish 2 goals.
1. I'd like to be able to read the rating value correctly. I know frames can have different values depending on the user. I'm specifically looking for the one that is displayed here by the Windows system properties.
2. Once I have the correct frame, I want to be able to write a different value back to the file. Say, go from 4 to 5 stars.

Neither of these options are working right now because as you can see by the comment in the code above, the Rating value for the frame is always zero. What am I missing?
LVL 21
Russ SuterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technical NinjaCommented:
Hi Russ,

I tried your code and it worked flawlessly for me. So I researched a bit more with the code and found something odd. Then I stumbled upon this explanation:
The purpose of this frame is to specify how good an audio file is. Many interesting applications could be found to this frame such as a playlist that features better audiofiles more often than others or it could be used to profile a person's taste and find other 'good' files by comparing people's profiles. The frame is very simple. It contains the email address to the user, one rating byte and a four byte play counter, intended to be increased with one for every time the file is played. The email is a terminated string. The rating is 1-255 where 1 is worst and 255 is best. 0 is unknown. If no personal counter is wanted it may be omitted. When the counter reaches all one's, one byte is inserted in front of the counter thus making the counter eight bits bigger in the same away as the play counter ("PCNT"). There may be more than one "POPM" frame in each tag, but only one with the same email address.

from here: http://id3.org/id3v2.3.0#Popularimeter

One easy way to fix this is - and again - strictly conditional this one, is to check User string by dynamically expanding the Tag in Debug View.

Regards,
Chinmay.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chinmay PatelChief Technical NinjaCommented:
Hi Russ,

Is TagLibSharp a mandatory library that you have to use or you are open to use any other library?

Regards,
Chinmay.
0
Russ SuterAuthor Commented:
I'd be fine with another library. I'm only using TagLibSharp because it was recommended on several other sites as I was looking for a way to solve this issue. If you have another suggestion I'd be more than happy to check it out.
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Chinmay PatelChief Technical NinjaCommented:
Please check Audio Tools for. Net Library.
0
Russ SuterAuthor Commented:
I just checked that out. The documentation says it only reads data. I need to be able to write also (see item # 2 in my original post).
0
Chinmay PatelChief Technical NinjaCommented:
It supports reading and writing both. Which document you are referring to?
0
Russ SuterAuthor Commented:
0
Chinmay PatelChief Technical NinjaCommented:
It's already discontinued. Please refer to the new one on Github.com.
0
Russ SuterAuthor Commented:
Thanks. I figured out that the issue was something wrong with the mp3 file itself. It seems to have been locked by another process and the tag didn't read and write correctly. After trying it again on a different mp3 file it did work.

That being said, the other library you pointed me to looks quite helpful as well. I now have something else to play with.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
mp3

From novice to tech pro — start learning today.