Solved

Code to run video on WindowsMediaPlayer component on a VB 6 form

Posted on 2004-08-04
13
626 Views
Last Modified: 2008-01-09
I have the following code to run video by first launching "WindowsMediaPlayer exe file installed on the computer" and then running .wmv file:

Public Function StartDoc(ByVal FileName As String, Optional CommandLine As String = "")

 StartDoc = ShellExecute(0 &, "Open", FileName, CommandLine, VbNullString, 1)

End Function
----
StartDoc "C\MyFolder\1.wmv"
-----
Q1. How can I revise above code to open my 1.wmv file through the control on the form (WindowsMediaPlayer component on a VB form)?

Q2. What is the code to switch video play to "WindowsMediaPlayer exe file installed on the computer" through a double-click action (directly on the component on the form).

Regards,

Mike
0
Comment
Question by:Mike Eghtebas
  • 5
  • 4
  • 2
  • +1
13 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
There is a Windows Media Player OCX that is placeable on the control.  You can add the ActiveX control by adding it through the Add Components dialog.

Bob
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
First a added the ActiveX control to tool box.  Then, I droped it on my form.  Now, I have "C:\MyFolder\1.wmv".  Please give me step by step direction from this point on.

Mike
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
Mike,

try like:

...
MediaPlayer1.FileName = "c:\test.wmv"
    MediaPlayer1.Play
...
0
 
LVL 19

Accepted Solution

by:
Shauli earned 500 total points
Comment Utility
'Lets say you load it form command button, then:
Private Sub Command1_Click()
    WindowsMediaPlayer1.URL = "C:\MyFolder\1.wmv"
End Sub

S
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
Wow.  This is great Shauli.  It works wonderfully.  Actually, I am us key press event to run the video (v or V).  When the video finishes, the image of last frame from the video stays on the form.

Q1. How do I clear it (the image of last frame from the video)?
Q2. Becuase ther is no close button for the video control, what will be the code to stop the video also clear the last frame image discussed above (I will us S or s key press to do that.  Also, I may a a button to click on it).

Furthermore, on doubl-click the screen fills the entire monitor.  This is so good.
----------

 ryancys,

MediaPlayer1.FileName = "c:\test.wmv"    <-- gave me an error (.Play isn't available through intelisense either.  I am in VB 6)
 MediaPlayer1.Play                                  <-- I was exited about command .Play thinking there might be .StopPlay or something similar for me to use it.

Regards,

Mike
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
To stop the movie, we can try like:

MediaPlayer1.Stop

FYI, i use M$ Media Player included from References (msdxm.ocx)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 19

Expert Comment

by:Shauli
Comment Utility
'To stop AND clear use the line below:
WindowsMediaPlayer1.Close

'The player clears itself once it finishes to play the video. So all that left is to clear if it was paused by the user, using the integrated pause button. For that you can use the line above as weel. As you will need to close the open url anyway.

S

0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Rust never sleeps, but I do  The question just goes on without you.   Just kick it and watch it go:)

Bob
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
Shauli,

When user makes cerain selection on the vb form, a lable becomes visible stating:

"Hit S to start video."    'of course when there is a video avaiable for the selection
-------
Via S keypress, video starts.  Upon S keypress, the lable changes to:

"Hit Q to quit video."

This works nicely.  "S" keystrok starts the video with "Pause" button on.
-------------
On WindowsMediaPlayer1, we also have "Play/ Pause" and "Stop" Buttons

Q3.  What is the code to "Pause" via a keystrok "P" not by click on the pause button (code to go to Keypress event of the form).  
Q4.  What is the code to "Play" via a keystrok "P" (second P strok) not by click on the play button (code to go to Keypress event of the form, I will need also to detect whether the video is playing or pause at the moment).

Do you want me post these items in a new question?

Regards,

Mike
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
That's it, just totally ignore my assistance:)

Bob
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
Hi Bob,

Do you have time to help me with Q3 and Q4?  I will post a new question for it.  Please note that the response fro Shauli was what worked for me.  

Regards,

Mike
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
I love to have fun with people.  It's always a race to see who get there first.  It's all about finding the right answer:)

Generally, it is acceptable practice to only ask one question at a time.  So my suggestion would be to create a new question for Q3 and Q4.

Bob
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now