Click here to Skip to main content
15,892,199 members
Articles / Desktop Programming / Win32

Rating Stars for Windows Media Player

Rate me:
Please Sign up or sign in to vote.
3.67/5 (2 votes)
16 Mar 2009CPOL2 min read 22.4K   468   8  
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.

VB
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --