Author Topic: Close Active X object not working.  (Read 1804 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Close Active X object not working.
« on: July 09, 2009, 05:53:22 PM »
This is a problem that Patrick and I encountered when answering a question over at CADTutor, the OP wanted to open Media Player, play a file, then, once the file had finished playing, close the player.

Patrick kindly provided this example to open the player:

Code: [Select]
(setq video "Une_video.avi")
(setq mp (vlax-create-object "WMPlayer.OCX"))
(vlax-invoke mp 'openPlayer (findfile video))
(vlax-dump-object mp T) ; to look full functions
(vlax-release-object mp)

I tried using this to get the play state of the file to no avail:

Code: [Select]
(setq video "Une_video.avi")
(setq mp (vlax-create-object "WMPlayer.OCX"))
(vlax-invoke mp 'openPlayer (findfile video))
(while
  (progn
    (setq pl (vlax-get-property mp 'playstate))
    (cond ((eq 3 pl)
           (vlax-invoke mp 'close))
          (t t ))))
(vlax-release-object mp)

And Parick later made this "kill" function, which is less than ideal, as a manually calculated delay must also be used:

Code: [Select]
(defun kill(qui / item meth1 meth2 obj WMI)
  (setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
        meth1 (vlax-invoke WMI 'ConnectServer nil nil nil nil nil nil nil nil)
        meth2 (vlax-invoke meth1 'ExecQuery "Select * from Win32_Process")
  )
  (vlax-for item meth2
    (and (setq obj (vlax-get item 'CommandLine)) (vl-string-search (strcase qui) (strcase obj))
      (vlax-invoke item 'Terminate)
    )
  )
  (foreach item (list WMI meth1 meth2)
    (vlax-release-object item)
  )
)

;(kill "wmplayer.exe")


I wondered if anyone here could offer any insight as to why we could not use methods/properties of the Active X object, after it is created, it would be much appreciated.   :?

Thanks,

Lee
« Last Edit: July 09, 2009, 06:11:37 PM by Lee Mac »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Close Active X object not working.
« Reply #1 on: July 10, 2009, 12:25:22 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

VVA

  • Newt
  • Posts: 166
Re: Close Active X object not working.
« Reply #2 on: July 10, 2009, 02:25:58 AM »
Can be still to try taskkill?
Code: [Select]
    (setq ws (vlax-get-or-create-object "wscript.shell"))
    (vlax-invoke-method ws
      "run"
      "taskkill /F /T /IM "wmplayer.exe""
      1
      :vlax-true
      )
(vlax-release-object ws)

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Close Active X object not working.
« Reply #3 on: July 10, 2009, 11:16:15 AM »
I think the problem is that WMP is not reporting the playstate status as you'd expect it to. Here are 2 dumps of the MP object, the first is when it's at rest, the second when it's playing a video:
Quote from: VLIDE
; IWMPPlayer4: IWMPPlayer4: Public interface.
; Property values:
;   cdromCollection (RO) = #<VLA-OBJECT IWMPCdromCollection 03231524>
;   closedCaption (RO) = #<VLA-OBJECT IWMPClosedCaption2 0323154c>
;   controls (RO) = #<VLA-OBJECT IWMPControls3 03231574>
;   currentMedia = nil
;   currentPlaylist = #<VLA-OBJECT IWMPPlaylist 0323159c>
;   dvd (RO) = #<VLA-OBJECT IWMPDVD 032315c4>
;   enableContextMenu = -1
;   enabled = -1
;   Error (RO) = #<VLA-OBJECT IWMPError 032315ec>
;   fullScreen = 0
;   isOnline (RO) = -1
;   isRemote (RO) = 0
;   mediaCollection (RO) = #<VLA-OBJECT IWMPMediaCollection2 03231614>
;   network (RO) = #<VLA-OBJECT IWMPNetwork 0323163c>
;   openState (RO) = 6
;   playerApplication (RO) = Exception occurred
;   playlistCollection (RO) = #<VLA-OBJECT IWMPPlaylistCollection 03231664>
;   playState (RO) = 0
;   settings (RO) = #<VLA-OBJECT IWMPSettings2 032224e0>
;   status (RO) = ""
;   stretchToFit = 0
;   uiMode = "full"
;   URL = ""
;   versionInfo (RO) = "11.0.6002.18005"
;   windowlessVideo = 0
; Methods supported:
;   close ()
;   launchURL (1)
;   newMedia (1)
;   newPlaylist (2)
;   openPlayer (1)
T
_$

nil
_$

; IWMPPlayer4: IWMPPlayer4: Public interface.
; Property values:
;   cdromCollection (RO) = #<VLA-OBJECT IWMPCdromCollection 0323168c>
;   closedCaption (RO) = #<VLA-OBJECT IWMPClosedCaption2 032316b4>
;   controls (RO) = #<VLA-OBJECT IWMPControls3 032316dc>
;   currentMedia = nil
;   currentPlaylist = #<VLA-OBJECT IWMPPlaylist 03231704>
;   dvd (RO) = #<VLA-OBJECT IWMPDVD 0323172c>
;   enableContextMenu = -1
;   enabled = -1
;   Error (RO) = #<VLA-OBJECT IWMPError 0323378c>
;   fullScreen = 0
;   isOnline (RO) = -1
;   isRemote (RO) = 0
;   mediaCollection (RO) = #<VLA-OBJECT IWMPMediaCollection2 032337b4>
;   network (RO) = #<VLA-OBJECT IWMPNetwork 032337dc>
;   openState (RO) = 6
;   playerApplication (RO) = Exception occurred
;   playlistCollection (RO) = #<VLA-OBJECT IWMPPlaylistCollection 03233804>
;   playState (RO) = 0
;   settings (RO) = #<VLA-OBJECT IWMPSettings2 032224e0>
;   status (RO) = ""
;   stretchToFit = 0
;   uiMode = "full"
;   URL = ""
;   versionInfo (RO) = "11.0.6002.18005"
;   windowlessVideo = 0
; Methods supported:
;   close ()
;   launchURL (1)
;   newMedia (1)
;   newPlaylist (2)
;   openPlayer (1)
Note that there are NO differences bewteen the 2. One would expect SOMETHING to be different, especially the playstate. I'm looking for a solution.....

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Close Active X object not working.
« Reply #4 on: July 10, 2009, 02:23:32 PM »
Yes, I found that result Jeff - but couldn't find a solution.