Set Song/Video position using the Windows Media Player control

Hi EE,

I am using Visual Basic 6 and have a Windows Media Player control on my form. I want to be able to set the position of the current file playing through the code - not by clicking the progress bar. I can get the current position in two formats - raw (1.04356834) and string (03:28) - but I just can't work out how to set the position.

Thank you very much for your help,

This is the code to get the raw position where WMP is the Windows Media Player control:
This is the code to get the string position where WMP is the Windows Media Player control:

Open in new window

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.


I just tested it with the WMP control, and the statement:

wmp.Controls.currentPosition = 30.04356834
works perfectly.

However, as the CurrentPositionString property is read-only, you cannot just jump to, for instance, the "03:21" position. If you want to do that, you may need to write a function to convert the "03:21" position to a Double, and then assign it to the currentposition property.

I hope that helped;


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
sabrehagenAuthor Commented:
Great, I'm such an idoit, I only tried with the string not the raw :(

To finish the question, how do you convert "03:21" to a double?
You can parse the string looking for Hr Min Sec and CDbl to get your position.
sabrehagenAuthor Commented:
Regrettably, I'm going to accept purquiz's answer, because even though it is right, I made the stupid mistake of only testing half the problem, the WRONG half :P If I hadn't given up, and tried to solve it myself, I'm sure I could have done it.

Thankyou anyway purquiz :)

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
Digital Audio

From novice to tech pro — start learning today.