WMP.DLL currently playing file


what i'm trying to do:


first start windows media player
then start a vb program that can "send" pause, play, prev next  to the already running WMP

i am looking to WMP.DLL, but i'm kinda lost
(Project->Reference->Windows Media player)

if i use this code:

Private Sub Command1_Click()
Dim tmp As WindowsMediaPlayer
Set tmp = New WindowsMediaPlayer
tmp.Controls.Next
Set tmp = Nothing
End Sub


nothing happens

how should i change this code so it works with an already running wmp?
LVL 13
Mark_FreeSoftwareAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark_FreeSoftwareAuthor Commented:

thanx for the time you took,

but none of the links provides info about sending info to a running WMP instance
vinnyd79Commented:
You could try using the keybd event api. Here is a simple example that will pause/play and stop media player. Try adding this to a form with 2 command buttons:


Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
            (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hwnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_CONTROL = &H11&
Private Const VK_P = &H50&
Private Const VK_S = &H53&

Private Sub Command1_Click()
' play / pause media player
Dim mpWin As Long, lObjhWnd As Long, x As Long
mpWin = FindWindow(vbNullString, "Windows Media Player")
If mpWin <> 0 Then
    x = SetForegroundWindow(mpWin)
    keybd_event VK_CONTROL, 0, 0, 0
    keybd_event VK_P, 0, 0, 0
    keybd_event VK_P, 0, KEYEVENTF_KEYUP, 0
    keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
End If
End Sub

Private Sub Command2_Click()
' stop media player
Dim mpWin As Long, lObjhWnd As Long, x As Long
mpWin = FindWindow(vbNullString, "Windows Media Player")
If mpWin <> 0 Then
    x = SetForegroundWindow(mpWin)
    keybd_event VK_CONTROL, 0, 0, 0
    keybd_event VK_S, 0, 0, 0
    keybd_event VK_S, 0, KEYEVENTF_KEYUP, 0
    keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
End If
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark_FreeSoftwareAuthor Commented:

thank you!

that did work very well, but with some digging i found these:


Const VK_VOLUME_MUTE = &HAD
Const VK_VOLUME_DOWN = &HAE
Const VK_VOLUME_UP = &HAF
Const VK_MEDIA_NEXT_TRACK = &HB0
Const VK_MEDIA_Prev_TRACK = &HB1
Const VK_MEDIA_STOP = &HB2
Const VK_MEDIA_PLAY_PAUSE = &HB3


so points go to you for pointing me in the good direction!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.