• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

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?
0
Mark_FreeSoftware
Asked:
Mark_FreeSoftware
  • 2
1 Solution
 
Mark_FreeSoftwareAuthor Commented:

thanx for the time you took,

but none of the links provides info about sending info to a running WMP instance
0
 
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
0
 
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!
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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now