Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-08-04
13
Medium Priority
?
671 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 54

Expert Comment

by:Ryan Chong
ID: 11722801
Mike,

try like:

...
MediaPlayer1.FileName = "c:\test.wmv"
    MediaPlayer1.Play
...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Accepted Solution

by:
Shauli earned 2000 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 54

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

971 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