views:

174

answers:

6

I want to be able to store information about a song that has been opened using my application. I would like for the user to be able to give the song a rating and this rating be loaded every time the users opens that file using my application.

I also need to know weather I should store the ratings in a database or an xml file.

A: 

I would store the ratings in a XML file, that way it's easy to edit from the outside, easy to read in .NET and you don't have to worry about shipping a database for something simple with you application.

Something like this might work for you:

<Songs>
  <Song Title="{SongTitle}">
    <Path>{Song path}</Path>
    <Rating>3</Rating>
  </Song>
</Songs>
Nathan W
In XML attributes use = and must be quoted. Element tags are case sensitve ("</songs>").
Roger Pate
+2  A: 

I would store it in a file as it is easier to keep with the mp3 file itself. If all you're doing is storing ratings, would you consider setting the ID3 rating field instead?

Bernard Chen
Could you provide some more info on the ID3 rating field? (Specificlly how to change and save it using C#)
Bob Dylan
+2  A: 

I would use a single-file, zero-config database. SQL Server Compact in your case.

I don't think XML is a good idea. XML shines in data interchange and storing very small amounts of information. In this case a user may rate thousands of tracks ( I have personally in online radios that allow ratings), and you may have lots of other information to store about the track.

Export and import using XML export procedures if you have to. Don't use it as your main datastore.

kervin
Sqlite is another popular single-file, zero-config database.
Roger Pate
A: 

For this type of very simple storage I don't think it really matters all that much. The pro's of XML is its very easy to deploy and its editable outside of your app. the con's are, its editible outside your application (could be good, could be bad, depends on your situation)

Maybe another option (just because you can ;-) is an OODBMS, check out DB4Objects, its seriously addictive and very, very cool.

Tim Jarvis
+2  A: 

C# ID3 Library is a .Net class library for editing id3 tags (v1-2.4). I would store the ratings directly into the comments section of the mp3 since id3v1 does not have many of the storage features that id3v2 does. If you want to store additional information for each mp3, what about placing a unique identifier on the mp3 and then having that do a database lookup?

I would be cautious about adding custom tags to mp3s as it is an easy way to ruin a large library. Also, I have gone down this road before and while I enjoyed the programming knowledge that came out of it, trying something like the iTunes SDK or Last FM might be a better route.

Kevin Lamb
Thanks! I had already downloaded the C# ID3 Lib, but didn't think about using the comments as a way to save the rating. This also allows me to use a better rating system then just 1-5.
Bob Dylan
+1  A: 

As mentioned earlier it is better to store such information in media file itself. And my suggestion is to use TagLib# lib for this (best media metadata lib I can find). Very powerful and easy to use.

arbiter