Solved

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

Posted on 2004-08-04
13
630 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 33

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 49

Expert Comment

by:Ryan Chong
ID: 11722801
Mike,

try like:

...
MediaPlayer1.FileName = "c:\test.wmv"
    MediaPlayer1.Play
...
0
 
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 33

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 49

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 33

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 33

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 33

Author Comment

by:Mike Eghtebas
ID: 11730670
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

932 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

14 Experts available now in Live!

Get 1:1 Help Now