Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Rating Stars for Windows Media Player

0.00/5 (No votes)
16 Mar 2009 1  
How to create stars to display the UserRating property in WMP.

Introduction

This small User Control displays the rating of a music file. Progress bars display one star with 20% rating, but the ratings of the AxWindowsMediaPlayer control are different, and not very logical. That's why I coded this small User Control.

Background

When I tried to display the rating of a media file with a progress bar, I got very weird results. I searched the Internet, but didn't really find a solution. What I did find was an article on MSDN about how the UserRating attribute works. I decided to try to write a small class, and publish it here, to help people with the same problem as me.

I'm just 16 years old, and have two years of programming experience, but never published my code on a site like CodeProject. I have learned a lot from this project, but I hope I can learn even more from your comments on the code :-)

Using the code

First, I had to think about how to display the right star with the right rating. Because I am not that good with GDI, I created two panels which contain five stars each. With a lot of trying, testing, and thinking, I got what I searched for.

If track <= 12 Then
    Panel1.Width = (track / 12) * _Star.Width
ElseIf track > 12 And track < 87 Then
    Panel1.Width = _Star.Width + ((((track - 12) / 24)) * _Star.Width)
ElseIf track >= 87 Then
    Panel1.Width = (_Star.Width * 4) + ((((track - 87) / 12)) * _Star.Width)
End If

track is the value of the UserRating. I figured out that the first star has a value of 12, the middle stars 24, and the last star 12 again. So, the system above shows the right star with the right rating, at the right moment. If not all the stars are needed, they are just "cut off" by the panel's width, and the user sees the second panel beneath that displays the gray stars.

Next, I created a nice mouse-over function which you can enable and disable in the property RateEnabled. When this property is enabled, the stars "glow" when the mouse hovers over them, and with a click, you can set a rating. When this happens, the custom event OnRate will be fired, with the new rating. You can also change the standard images with the other ones.

Untitled-2.png

All the custom properties and events of my class

Points of interest

I'd never created a User Control before with a custom event. I have learned some new stuff. This is also my first contribution to The Code Project, and I hope it is appreciated. Comments are welcome, there is always more to learn for me.

History

  • 13th March, 2009: Initial post.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here