Solved

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

Posted on 2004-08-04
13
643 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
ID: 11722580
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 34

Author Comment

by:Mike Eghtebas
ID: 11722737
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 50

Expert Comment

by:Ryan Chong
ID: 11722801
Mike,

try like:

...
MediaPlayer1.FileName = "c:\test.wmv"
    MediaPlayer1.Play
...
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 19

Accepted Solution

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

S
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 11723187
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 50

Expert Comment

by:Ryan Chong
ID: 11723288
To stop the movie, we can try like:

MediaPlayer1.Stop

FYI, i use M$ Media Player included from References (msdxm.ocx)
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11724793
'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
ID: 11725936
Rust never sleeps, but I do  The question just goes on without you.   Just kick it and watch it go:)

Bob
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 11729725
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
ID: 11729846
That's it, just totally ignore my assistance:)

Bob
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 11729932
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
ID: 11729970
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 34

Author Comment

by:Mike Eghtebas
ID: 11730670
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

856 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