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:
(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:
(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:
(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