Questions regarding code for embedded Media Player (1 Viewer)

kyuball

Registered User.
Local time
Today, 10:22
Joined
Jul 6, 2009
Messages
66
I have a question regarding controlling a Windows Media Player embedded into an Access Form. I am currently on Access 2003 through Windows 7 32bit and using Windows Media Player 12.

I am building a database for the various sketch comedy show videos that I have downloaded over time (I am a fanatic of Kids In The Hall, Upright Citizens Brigade and the ilk.) I am trying to file them by certain segments of the entire episode so that I have a list of my favorite sketches to choose from and watch. The data is being entered into a table through a form and is built something like this: ID(PK), name (Just a name for the title I give it), series (an ID from another table that lists the various sketch show series), starttime (Format: h:mm:ss and indicates the point in the video file where the particular segment starts), endtime (same format as before except that this indicates end time), runtime (calculated based on start and end time through the entry form… just a bit if nerdy info I like to have.. not necessarily needed but not necessarily getting in the way…) and URL (location in my computer where file is located.) So a typical entry would go something like this:

ID: 4
name: Crushing Your Head vs. Pinching Your Face
series: 3 (In this case indicating that it is Kids In The Hall)
starttime: 0:12:32
endtime: 0:19:45
runtime: 0:07:13
URL: C:/Users/My_Videos/kidsinthehallse2ep4.wmv

Once the data is in, I can view it through a Windows Media Player that I have embedded on a form (I was originally going to just hyperlink the file URL but thanks to another thread here, found out that this is the MUCH cooler way to do it!) using the code below:

Private Sub Form_Load()

Me.WindowsMediaPlayer03.URL = Me.URL

End Sub

The code works fine but starts the video at 0:00:00 of the file and I would have to manually search through the video file for the segment I want to watch based on the start and end time info that is displayed. I was hoping to go one further and write some kind of code that would start playing the video file at the beginning of the segment (in the case of the example above at 0:12:32) and maybe even one that stops it once it reaches the end time.

I went into the properties of the WMP ActiveX control and noticed that under the Advanced tab that there was something called “Current position” that seems to control the start time of the file calculated in seconds (I can get a text box to calculate the seconds using the formula ([starttime]*24)*3600), so I tried writing code for it something like Me.WindowsMediaPlayer03.currentPosition = Me.Text12 but that didn’t work (Currentposition was one of the things listed when I looked up available commands for code pertaining to WMP)

Any suggestions for how I can do this or is this just a pipe dream for now?
 

kyuball

Registered User.
Local time
Today, 10:22
Joined
Jul 6, 2009
Messages
66
So I have been devoting some time to this lately and got around to using a slider control and using the min and max within that control to set start time and end time on the slider and letting the slider limit which part of the video file is available. However, the slider does not move along with the video and therefore can't actually enforce the end time (the video can play past the end time if the slider position is not manually changed...)

I discovered something called the WMPSliderCtrl and that seems to be the control for the slider on the Windows Media Player itself (?) However, when I did something like below, I got the old Run time error 91:

Private mediap as WindowsMediaPlayer

Private Sub Form_Load()

Set mediap = Me.WindowsMediaPlayer03.Object
Dim slider As WMPSliderCtrl

mediap.URL = Me.URL
mediap.Controls.currentPosition = Me.Text12
slider.min = Me.Text12 (Calculated time into seconds)
slider.max = Me.Text14 (Calculated time into seconds)

End Sub

But then I get the Runtime error 91 when I open up the form which probably means I have not somehow associated the WMPSliderCtrl with the slider that is internal to the Media Player that is on the form (?) Is there any way to do this?
 

kyuball

Registered User.
Local time
Today, 10:22
Joined
Jul 6, 2009
Messages
66
Thanks, darbid for your quick response! I tried SelectionStart/ SelectionEnd but now it tells me that Object does not support property/ method. Any way to invoke this property in Access?

The actual lines of code I wrote was:

mediap.SelectionStart = Me.Text12
mediap.SelectionEnd = Me.Text14
 

darbid

Registered User.
Local time
Today, 19:22
Joined
Jun 26, 2008
Messages
1,428
sorry, I was incorrect that reference is not to the same mediaplayer you are using. I am not sure what you can use.
 

darbid

Registered User.
Local time
Today, 19:22
Joined
Jun 26, 2008
Messages
1,428
Hey kyuball,

How is it going, are you getting anywhere?

I have had another look at the MSDN stuff. I do not really understand the material there. Personally it looks like when they built the library to communicate between the ActiveX control and VBA (COM) they cut some corners in a major way.

The only thing I could find was STEP see here http://msdn.microsoft.com/en-us/library/dd563182(VS.85).aspx

Stupidly it uses Frames and not seconds, but if you do a calculation of how many frames per second you have then you will be able to then use seconds.

I hope this GUESS helps you.
 

kyuball

Registered User.
Local time
Today, 10:22
Joined
Jul 6, 2009
Messages
66
Hey darbid,

Thanks for all of the research you are doing! If we were in the same area, I would take you out for a drink!

I tried your solution and I am still running into the problem of being able to associate an interal control like WMPSliderCtrl or or SelectionStart (which still seems like the best solution if I can get into it...) with the actual Windows Media Player that is on the form (Set mediap = Me.WindowsMediaPlayer03.Object) Any way to do this? I already set a private declaration at the beginning of the form (Private mediap as WindowsMediaPlayer)...
 

darbid

Registered User.
Local time
Today, 19:22
Joined
Jun 26, 2008
Messages
1,428
attach a little mdb example. I will add my own video file to it and see what you are doing.
 

darbid

Registered User.
Local time
Today, 19:22
Joined
Jun 26, 2008
Messages
1,428
I tried your solution and I am still running into the problem of being able to associate an interal control like WMPSliderCtrl or or SelectionStart (which still seems like the best solution if I can get into it...)
SelectionStart is not available for the activeX control on a form. I was wrong in giving you this reference.
 

kyuball

Registered User.
Local time
Today, 10:22
Joined
Jul 6, 2009
Messages
66
Hey darbid,

Thanks for your continued efforts! Here is an abbreviated version of the mdb. And I must say so myself, it's not a half bad video organizing/ viewing tool, either!
 

Attachments

  • comedydb.mdb
    588 KB · Views: 201

darbid

Registered User.
Local time
Today, 19:22
Joined
Jun 26, 2008
Messages
1,428
Here is how to set the starting position

Code:
mediap.settings.autoStart = False
    mediap.URL = Me.videourl
    mediap.Controls.currentPosition = 50
    mediap.Controls.play
I think this only works on short videos. On long ones Media player must first "Find" the position. Try it first but then follow on.


You need to sink the events of the media player like this
Code:
Private WithEvents mediap As WindowsMediaPlayer
Then this event will be available
Code:
Private Sub WindowsMediaPlayer8_PositionChange(ByVal oldPosition As Double, ByVal newPosition As Double)



End Sub
this also - here you need to check that the player is at the ready state 10 I think BEFORE you play at your selected position.
Code:
Private Sub WindowsMediaPlayer8_PlayStateChange(ByVal NewState As Long)

End Sub
As for stopping I am not sure how to do this. There is one duration item but it is not in use.

I think you need to follow this yourself. Ie with a timer.

There are two ways you could do this.

1. This is a little but overkill but you could set up the timer for 1 second. You could then GET the current position. If position = endtime then STOP

2. You could simply set the timer to the endtime and just stop it.
The problem with this is that if people stop the video or move around it will stop early.

by the way how do you enter a time in your forms/table that mask does not work for me. :)
 

darbid

Registered User.
Local time
Today, 19:22
Joined
Jun 26, 2008
Messages
1,428
couple of other suggestions

I do not think you should ask them to give you the duration of the movie. They do not know it exactly especially if they are using bits cut from movies etc

Code:
mediap.currentMedia.duration
This will give you it, but you need to make sure mediaplayer is ready before getting it.

Also why is your form to show videos using a recordsource. Do you plan on something else. If it is simply showing a video I would suggest you pass the variables you need with the openargs part of the open command.

I would have thought even more "professional" would be to put those two forms together. Ie left the list of videos and on the right the video.

Mediaplayer has a full screen mode so you could put that as a button on the form in case they want a bigger picture.
 

kyuball

Registered User.
Local time
Today, 10:22
Joined
Jul 6, 2009
Messages
66
Here is how to set the starting position

Code:
mediap.settings.autoStart = False
    mediap.URL = Me.videourl
    mediap.Controls.currentPosition = 50
    mediap.Controls.play
I think this only works on short videos. On long ones Media player must first "Find" the position. Try it first but then follow on.

This one I had no problem with as you can see in the database I posted. As far as I can tell, once time is converted into seconds (e.g. 0:03:15 in h:nn:ss format equals 195 seconds) it can find the current position in any kind of video file that is compatible with WMP. This is how I got it to start at the correct point in the video...

You need to sink the events of the media player like this
Code:
Private WithEvents mediap As WindowsMediaPlayer
Then this event will be available
Code:
Private Sub WindowsMediaPlayer8_PositionChange(ByVal oldPosition As Double, ByVal newPosition As Double)
 
 
 
End Sub
this also - here you need to check that the player is at the ready state 10 I think BEFORE you play at your selected position.
Code:
Private Sub WindowsMediaPlayer8_PlayStateChange(ByVal NewState As Long)
 
End Sub

This bit of info is giving me some insight but I am not sure how to use these events to do what I want. Perhaps disabling the autostart setting on the WMP and then starting it up on its own would trigger the Playstatechange event, but I can't seem to find any useful function within these event procedures...

As for stopping I am not sure how to do this. There is one duration item but it is not in use.

I think you need to follow this yourself. Ie with a timer.

There are two ways you could do this.

1. This is a little but overkill but you could set up the timer for 1 second. You could then GET the current position. If position = endtime then STOP

2. You could simply set the timer to the endtime and just stop it.
The problem with this is that if people stop the video or move around it will stop early.

I thought about this as well and maybe its because I am still VERY amateurish when it comes to Access (as you can tell by the db I posted), but there seems to be no way of setting the timer interval with VBA. Like it seems you write in 5000 in the events and that is that. Also it seems like the OnTimer event triggers on its own and can't be reset even if I could manipulate the timer interval. These were the two things that stopped me when I thought about using a slider control and turning off the WMP slider. I know it would not have made the WMP Active X as much fun to play with but at least it would have let me control things...

by the way how do you enter a time in your forms/table that mask does not work for me. :)

I set the table field as Date/Time and set the format to h:nn:ss and then set the input mask as 9:00:00;0;0.
 

kyuball

Registered User.
Local time
Today, 10:22
Joined
Jul 6, 2009
Messages
66
couple of other suggestions

I do not think you should ask them to give you the duration of the movie. They do not know it exactly especially if they are using bits cut from movies etc

Code:
mediap.currentMedia.duration
This will give you it, but you need to make sure mediaplayer is ready before getting it.

Yeah, I tried using duration, but found that it was read only and static, therefore not very useful for what I wanted to do.

Also why is your form to show videos using a recordsource. Do you plan on something else. If it is simply showing a video I would suggest you pass the variables you need with the openargs part of the open command.

Yeah, I use a recordsource because I have other bits o' info displayed on the form like actors in the sketch, times (as you can see on the one I posted), year and other nerdy junk...

I would have thought even more "professional" would be to put those two forms together. Ie left the list of videos and on the right the video.

Mediaplayer has a full screen mode so you could put that as a button on the form in case they want a bigger picture.

That's a really cool idea! Or perhaps even like a "quick preview" screen form in a fused form like you are suggesting and then playing it in full screen using a command button!

However, I am still having problems with limiting time thing....
 

darbid

Registered User.
Local time
Today, 19:22
Joined
Jun 26, 2008
Messages
1,428
This one I had no problem with as you can see in the database I posted. As far as I can tell, once time is converted into seconds (e.g. 0:03:15 in h:nn:ss format equals 195 seconds) it can find the current position in any kind of video file that is compatible with WMP. This is how I got it to start at the correct point in the video...
Good but I think it helps to make it work more smoothly.


This bit of info is giving me some insight but I am not sure how to use these events to do what I want. Perhaps disabling the autostart setting on the WMP and then starting it up on its own would trigger the Playstatechange event, but I can't seem to find any useful function within these event procedures...
I add this because I think on long movies if you set a position and play it straight away you might get an error. IN THEORY. Buy using the playstatechange event you will be able to track the playstate of the mediaplayer. When it has a play state of 10 then it is ready. If you add a new URL and ask for the duration straight away then it will show 0. This is an example of why you need this.

I thought about this as well and maybe its because I am still VERY amateurish when it comes to Access (as you can tell by the db I posted), but there seems to be no way of setting the timer interval with VBA. Like it seems you write in 5000 in the events and that is that. Also it seems like the OnTimer event triggers on its own and can't be reset even if I could manipulate the timer interval. These were the two things that stopped me when I thought about using a slider control and turning off the WMP slider. I know it would not have made the WMP Active X as much fun to play with but at least it would have let me control things...

Just before you add a URL add a ME.TimerInterval = 1000

Then add the forms Timer event. This is going to be fired every second.
I am worried about it firing so often so you will have to test this. Maybe you need to put the word "Doevents" in this event to let your CPU keep up.

Then in this event put - if duration = endtime then STOP

To stop the timer you just put Me.Timerinterval = 0

Also because I am worried about the timer setting off ever second you might want to stop the timer and start it again if the Playerstate changes to a pause.

I set the table field as Date/Time and set the format to h:nn:ss and then set the input mask as 9:00:00;0;0.
If I enter in the start field this 1:00 it will not let me out of the field.
 

darbid

Registered User.
Local time
Today, 19:22
Joined
Jun 26, 2008
Messages
1,428
Yeah, I tried using duration, but found that it was read only and static, therefore not very useful for what I wanted to do.
see above as to why it is useful. Also As I said the exact duration of a movie file is different to the movie length. If you mean movie length then fine but if you are technically needing the duration of the movie file then use this property.[/quote]

That's a really cool idea! Or perhaps even like a "quick preview" screen form in a fused form like you are suggesting and then playing it in full screen using a command button!

However, I am still having problems with limiting time thing....
In fact a button is not needed. Insert the double click event and then make it full screen on double click. Then also use track on I think the form or the mediaplayer the key down/key press event of ESC. If this event is fired and this key is being pressed and if it is full screen then minimize it again. (That would make it just like YouTube :))
 

kyuball

Registered User.
Local time
Today, 10:22
Joined
Jul 6, 2009
Messages
66
If I enter in the start field this 1:00 it will not let me out of the field.

Because the input mask is set to h:nn:ss, you have to put in five digits: one for the hour, two for the minutes and two for the seconds. So if you want to put in 1:00 as in one minute, you have to enter 0:01:00 or if it's 1:00 as in one hour, then you have to enter 1:00:00.

I did this to ensure that the time is entered in correct format and so that the db will recognize it as something equal to elapsed time and not serialized date or time (e.g., 0:00 would equal 12:00AM in Microsoft's time format.) Since the calculation for say current position needs to be calucated off of this, it was important for me to maintain that format.
 

kyuball

Registered User.
Local time
Today, 10:22
Joined
Jul 6, 2009
Messages
66
DARBID, YOU'RE A FRIGGIN' GENIUS!!!

OK, so I tried using the timer to keep track of where the play back is on the media is at any given time. I tried duration and that did not work , but current position did! Using this method, it showed me that current position is indeed not static and can be used to limit playback time!!

I haven't actually implemented it yet, as I am at work and do not access to anything but the little example I built, but being able to see the numerical progress of the playback time is the breakthrough I needed! And there was no strain on the CPU from having the timer fire off every second!

When I have a working version of this thing, should I post it?
 

darbid

Registered User.
Local time
Today, 19:22
Joined
Jun 26, 2008
Messages
1,428
DARBID, YOU'RE A FRIGGIN' GENIUS!!!

OK, so I tried using the timer to keep track of where the play back is on the media is at any given time. I tried duration and that did not work , but current position did! Using this method, it showed me that current position is indeed not static and can be used to limit playback time!!

I haven't actually implemented it yet, as I am at work and do not access to anything but the little example I built, but being able to see the numerical progress of the playback time is the breakthrough I needed! And there was no strain on the CPU from having the timer fire off every second!

When I have a working version of this thing, should I post it?

Yeh I never meant to use duration for checking. But if you are in full screen mode you might have to check to see if it is eneded so that you can take it automatically out of full screan mode. If you are going to watch movies with this, I would take the duration and add it to the current time and show the end time. That would be a cool little feature.

I am glad it worked. I like using VBA to do things like that. You will eventually have a really little media browser.

I think an example would be good for the forum. It is good to give back. The only problem I ever have is that my code gets implemented and it is hard to take it back out in an example.

Good luck.
 

Users who are viewing this thread

Top Bottom