VLC (Media Player) UDF


SUBMITTED BY: Guest

DATE: May 30, 2013, 7:57 a.m.

FORMAT: Text only

SIZE: 19.8 kB

HITS: 893

  1. #include-once
  2. #include <IE.au3>
  3. #Region Header
  4. #cs
  5. Title: VLC UDF Library for AutoIt3
  6. Filename: VLC.au3
  7. Description: A collection of functions for creating and controlling a VLC control in AutoIT
  8. Author: seangriffin
  9. Version: V0.3
  10. Last Update: 17/05/10
  11. Requirements: AutoIt3 3.2 or higher,
  12. A VLC version greater than 0.8.5 installed
  13. Changelog:
  14. --------17/05/10----------- v0.3
  15. Added the function _GUICtrlVLC_GetVolume.
  16. Added the function _GUICtrlVLC_SetVolume.
  17. Added the function _GUICtrlVLC_GetMute.
  18. Added the function _GUICtrlVLC_SetMute.
  19. --------15/05/10----------- v0.2
  20. Changed _GUICtrlVLC_GetState to return 0 if no playlist items.
  21. Changed _GUICtrlVLC_Pause to return 0 if no playlist items.
  22. Changed _GUICtrlVLC_Stop to return 0 if no playlist items.
  23. Changed _GUICtrlVLC_SeekRelative to return 0 if no playlist items.
  24. Changed _GUICtrlVLC_SeekAbsolute to return 0 if no playlist items.
  25. Added error handling to all functions.
  26. Added the function _VLCErrorHandlerRegister.
  27. Added the function __VLCInternalErrorHandler.
  28. ---------08/05/10---------- v0.1
  29. Initial release.
  30. Note that a clipping problem currently exists in the VLC control.
  31. #ce
  32. #EndRegion Header
  33. #Region Global Variables and Constants
  34. Global $oVLCErrorHandler, $sVLCUserErrorHandler
  35. #EndRegion Global Variables and Constants
  36. #Region Core functions
  37. ; #FUNCTION# ;===============================================================================
  38. ;
  39. ; Name...........: _GUICtrlVLC_Create()
  40. ; Description ...: Creates a VLC control.
  41. ; Syntax.........: _GUICtrlVLC_Create($left, $top, $width, $height)
  42. ; Parameters ....: $left - The left side of the control.
  43. ; $top - The top of the control.
  44. ; $width - The width of the control
  45. ; $height - The height of the control
  46. ; Return values .: On Success - Returns the identifier (controlID) of the new control.
  47. ; On Failure - Returns False.
  48. ; Author ........: seangriffin
  49. ; Modified.......:
  50. ; Remarks .......: This function must be used before any other function in the UDF is used.
  51. ; There is currently a clipping problem with the control, where the video
  52. ; is overdrawn by any other window that overlaps it. There is no known
  53. ; solution at this time.
  54. ;
  55. ; Related .......:
  56. ; Link ..........:
  57. ; Example .......: Yes
  58. ;
  59. ; ;==========================================================================================
  60. Func _GUICtrlVLC_Create($left, $top, $width, $height)
  61. Local Const $html = _
  62. "<style type=""text/css"">html, body, vlc {margin: 0px; padding: 0px; overflow: hidden;}</style>" & @CRLF & _
  63. "<object classid=""clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921""" & @CRLF & _
  64. "codebase=""http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab""" & @CRLF & _
  65. "width=""" & $width & """ height=""" & $height & """" & @CRLF & _
  66. "id=""vlc"" events=""True"">" & @CRLF & _
  67. "</object>"
  68. $oIE = _IECreateEmbedded ()
  69. $oIEActiveX = GUICtrlCreateObj($oIE, $left, $top, $width-4, $height-4)
  70. _IENavigate($oIE, "about:blank")
  71. _IEDocWriteHTML($oIE, $html)
  72. $vlc = _IEGetObjByName($oIE, "vlc")
  73. ; Clear any current VLC errors
  74. $oVLCErrorHandler.WinDescription = ""
  75. ; Check VLC version info. as a means to determine if the Active X control is installed
  76. $vlc.versionInfo()
  77. ; If an error (the ActiveX control is not installed), then return False
  78. if StringInStr($oVLCErrorHandler.WinDescription, "Unknown name") > 0 Then
  79. GUICtrlDelete($oIEActiveX)
  80. _IEQuit($oIE)
  81. Return False
  82. EndIf
  83. Return $vlc
  84. EndFunc
  85. ; #FUNCTION# ;===============================================================================
  86. ;
  87. ; Name...........: _GUICtrlVLC_Add
  88. ; Description ...: Adds a video to the playlist of a VLC control.
  89. ; Syntax.........: _GUICtrlVLC_Add($vlc, $path)
  90. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  91. ; $path - The full path, including filename, of the video to add.
  92. ; Return values .: On Success - Returns a number as an item identifier in playlist.
  93. ; On Failure - Returns False.
  94. ; Author ........: seangriffin
  95. ; Modified.......:
  96. ; Remarks .......:
  97. ; Related .......:
  98. ; Link ..........:
  99. ; Example .......: Yes
  100. ;
  101. ; ;==========================================================================================
  102. Func _GUICtrlVLC_Add($vlc, $path)
  103. if IsObj($vlc) = False Then Return False
  104. Return $vlc.playlist.add("file:///" & $path)
  105. EndFunc
  106. ; #FUNCTION# ;===============================================================================
  107. ;
  108. ; Name...........: _GUICtrlVLC_Play
  109. ; Description ...: Plays a video in the playlist of a VLC control.
  110. ; Syntax.........: _GUICtrlVLC_Play($vlc, $item)
  111. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  112. ; $item - The item in playlist to play, as returned by _GUICtrlVLC_Add.
  113. ; Return values .: On Success - Returns True.
  114. ; On Failure - Returns False.
  115. ; Author ........: seangriffin
  116. ; Modified.......:
  117. ; Remarks .......:
  118. ; Related .......:
  119. ; Link ..........:
  120. ; Example .......: Yes
  121. ;
  122. ; ;==========================================================================================
  123. Func _GUICtrlVLC_Play($vlc, $item)
  124. if IsObj($vlc) = False Then Return False
  125. $vlc.playlist.playItem($item)
  126. Return True
  127. EndFunc
  128. ; #FUNCTION# ;===============================================================================
  129. ;
  130. ; Name...........: _GUICtrlVLC_Pause
  131. ; Description ...: Pauses and unpauses the playing video.
  132. ; Syntax.........: _GUICtrlVLC_Pause($vlc)
  133. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  134. ; Return values .: On Success - Returns True.
  135. ; On Failure - Returns False.
  136. ; Author ........: seangriffin
  137. ; Modified.......:
  138. ; Remarks .......: Each time this function is called, the paused state of the video is toggled.
  139. ; Related .......:
  140. ; Link ..........:
  141. ; Example .......: Yes
  142. ;
  143. ; ;==========================================================================================
  144. Func _GUICtrlVLC_Pause($vlc)
  145. if IsObj($vlc) = False Then Return False
  146. if $vlc.playlist.items.count = 0 Then
  147. Return 0
  148. Else
  149. $vlc.playlist.togglePause()
  150. EndIf
  151. EndFunc
  152. ; #FUNCTION# ;===============================================================================
  153. ;
  154. ; Name...........: _GUICtrlVLC_Stop
  155. ; Description ...: Stops the playing video.
  156. ; Syntax.........: _GUICtrlVLC_Stop($vlc)
  157. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  158. ; Return values .: On Success - Returns True.
  159. ; On Failure - Returns False.
  160. ; Author ........: seangriffin
  161. ; Modified.......:
  162. ; Remarks .......:
  163. ; Related .......:
  164. ; Link ..........:
  165. ; Example .......: Yes
  166. ;
  167. ; ;==========================================================================================
  168. Func _GUICtrlVLC_Stop($vlc)
  169. if IsObj($vlc) = False Then Return False
  170. if $vlc.playlist.items.count = 0 Then
  171. Return 0
  172. Else
  173. $vlc.playlist.stop()
  174. EndIf
  175. EndFunc
  176. ; #FUNCTION# ;===============================================================================
  177. ;
  178. ; Name...........: _GUICtrlVLC_Clear
  179. ; Description ...: Clears the playlist of a VLC control (removes all videos).
  180. ; Syntax.........: _GUICtrlVLC_Clear($vlc)
  181. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  182. ; Return values .: On Success - Returns True.
  183. ; On Failure - Returns False.
  184. ; Author ........: seangriffin
  185. ; Modified.......:
  186. ; Remarks .......:
  187. ; Related .......:
  188. ; Link ..........:
  189. ; Example .......: Yes
  190. ;
  191. ; ;==========================================================================================
  192. Func _GUICtrlVLC_Clear($vlc)
  193. if IsObj($vlc) = False Then Return False
  194. $vlc.playlist.items.clear()
  195. while $vlc.playlist.items.count > 0
  196. WEnd
  197. Sleep(250)
  198. Return True
  199. EndFunc
  200. ; #FUNCTION# ;===============================================================================
  201. ;
  202. ; Name...........: _GUICtrlVLC_SeekRelative
  203. ; Description ...: Seek a relative number of milliseconds through the playing video.
  204. ; Syntax.........: _GUICtrlVLC_SeekRelative($vlc, $time)
  205. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  206. ; $time - A number of milliseconds to seek (negative values seek backwards).
  207. ; Return values .: On Success - Returns True.
  208. ; On Failure - Returns False.
  209. ; Author ........: seangriffin
  210. ; Modified.......:
  211. ; Remarks .......:
  212. ; Related .......:
  213. ; Link ..........:
  214. ; Example .......: Yes
  215. ;
  216. ; ;==========================================================================================
  217. Func _GUICtrlVLC_SeekRelative($vlc, $time)
  218. if IsObj($vlc) = False Then Return False
  219. if $vlc.playlist.items.count = 0 Then
  220. Return 0
  221. Else
  222. $vlc.input.time = $vlc.input.time + $time
  223. EndIf
  224. EndFunc
  225. ; #FUNCTION# ;===============================================================================
  226. ;
  227. ; Name...........: _GUICtrlVLC_SeekAbsolute
  228. ; Description ...: Seek to an absolute location in time in the playing video.
  229. ; Syntax.........: _GUICtrlVLC_SeekAbsolute($vlc, $time)
  230. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  231. ; $time - The number of milliseconds from the start of the video to seek to.
  232. ; Return values .: On Success - Returns True.
  233. ; On Failure - Returns False.
  234. ; Author ........: seangriffin
  235. ; Modified.......:
  236. ; Remarks .......:
  237. ; Related .......:
  238. ; Link ..........:
  239. ; Example .......: Yes
  240. ;
  241. ; ;==========================================================================================
  242. Func _GUICtrlVLC_SeekAbsolute($vlc, $time)
  243. if IsObj($vlc) = False Then Return False
  244. if $vlc.playlist.items.count = 0 Then
  245. Return 0
  246. Else
  247. $vlc.input.time = $time
  248. EndIf
  249. EndFunc
  250. ; #FUNCTION# ;===============================================================================
  251. ;
  252. ; Name...........: _GUICtrlVLC_GetState
  253. ; Description ...: Get the current state of the playing video.
  254. ; Syntax.........: _GUICtrlVLC_GetState($vlc)
  255. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  256. ; Return values .: On Success - Returns a number representing the state of the video:
  257. ; (IDLE=0, OPENING=1, BUFFERING=2, PLAYING=3, PAUSED=4, STOPPING=5, ENDED=6, ERROR=7)
  258. ; On Failure - Returns 0.
  259. ; Author ........: seangriffin
  260. ; Modified.......:
  261. ; Remarks .......:
  262. ; Related .......:
  263. ; Link ..........:
  264. ; Example .......: Yes
  265. ;
  266. ; ;==========================================================================================
  267. Func _GUICtrlVLC_GetState($vlc)
  268. if IsObj($vlc) = False Then Return False
  269. if $vlc.playlist.items.count = 0 Then
  270. Return 0
  271. Else
  272. Return $vlc.input.state
  273. EndIf
  274. EndFunc
  275. ; #FUNCTION# ;===============================================================================
  276. ;
  277. ; Name...........: _GUICtrlVLC_GetLength
  278. ; Description ...: Get the length of the playing video.
  279. ; Syntax.........: _GUICtrlVLC_GetLength($vlc)
  280. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  281. ; Return values .: On Success - Returns the length of the video in milliseconds.
  282. ; On Failure - Returns False.
  283. ; Author ........: seangriffin
  284. ; Modified.......:
  285. ; Remarks .......:
  286. ; Related .......:
  287. ; Link ..........:
  288. ; Example .......: Yes
  289. ;
  290. ; ;==========================================================================================
  291. Func _GUICtrlVLC_GetLength($vlc)
  292. if IsObj($vlc) = False Then Return False
  293. Return $vlc.input.length
  294. EndFunc
  295. ; #FUNCTION# ;===============================================================================
  296. ;
  297. ; Name...........: _GUICtrlVLC_GetMute
  298. ; Description ...: Gets the mute setting of the playing video.
  299. ; Syntax.........: _GUICtrlVLC_GetMute($vlc)
  300. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  301. ; Return values .: If muted - Returns True.
  302. ; If not muted - Returns False.
  303. ; Author ........: seangriffin
  304. ; Modified.......:
  305. ; Remarks .......:
  306. ; Related .......:
  307. ; Link ..........:
  308. ; Example .......: Yes
  309. ;
  310. ; ;==========================================================================================
  311. Func _GUICtrlVLC_GetMute($vlc)
  312. if IsObj($vlc) = False Then Return False
  313. Return $vlc.audio.mute
  314. EndFunc
  315. ; #FUNCTION# ;===============================================================================
  316. ;
  317. ; Name...........: _GUICtrlVLC_GetTime
  318. ; Description ...: Get the absolute position of the playing video.
  319. ; Syntax.........: _GUICtrlVLC_GetTime($vlc)
  320. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  321. ; Return values .: On Success - Returns the position of the playing video in milliseconds.
  322. ; On Failure - Returns False.
  323. ; Author ........: seangriffin
  324. ; Modified.......:
  325. ; Remarks .......:
  326. ; Related .......:
  327. ; Link ..........:
  328. ; Example .......: Yes
  329. ;
  330. ; ;==========================================================================================
  331. Func _GUICtrlVLC_GetTime($vlc)
  332. if IsObj($vlc) = False Then Return False
  333. Return $vlc.input.time
  334. EndFunc
  335. ; #FUNCTION# ;===============================================================================
  336. ;
  337. ; Name...........: _GUICtrlVLC_GetVolume
  338. ; Description ...: Gets the volume of the playing video.
  339. ; Syntax.........: _GUICtrlVLC_GetVolume($vlc)
  340. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  341. ; Return values .: On Success - Returns the percentage of the volume [0-200].
  342. ; On Failure - Returns False.
  343. ; Author ........: seangriffin
  344. ; Modified.......:
  345. ; Remarks .......:
  346. ; Related .......:
  347. ; Link ..........:
  348. ; Example .......: Yes
  349. ;
  350. ; ;==========================================================================================
  351. Func _GUICtrlVLC_GetVolume($vlc)
  352. if IsObj($vlc) = False Then Return False
  353. Return $vlc.audio.volume
  354. EndFunc
  355. ; #FUNCTION# ;===============================================================================
  356. ;
  357. ; Name...........: _GUICtrlVLC_SetMute
  358. ; Description ...: Mutes and unmutes the volume of the playing video.
  359. ; Syntax.........: _GUICtrlVLC_SetMute($vlc, $toggle)
  360. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  361. ; $toggle - boolean value to mute and ummute the audio.
  362. ; Return values .: On Success - Returns True.
  363. ; On Failure - Returns False.
  364. ; Author ........: seangriffin
  365. ; Modified.......:
  366. ; Remarks .......:
  367. ; Related .......:
  368. ; Link ..........:
  369. ; Example .......: Yes
  370. ;
  371. ; ;==========================================================================================
  372. Func _GUICtrlVLC_SetMute($vlc, $toggle)
  373. if IsObj($vlc) = False Then Return False
  374. $vlc.audio.mute = $toggle
  375. Return True
  376. EndFunc
  377. ; #FUNCTION# ;===============================================================================
  378. ;
  379. ; Name...........: _GUICtrlVLC_SetVolume
  380. ; Description ...: Sets the volume of the playing video.
  381. ; Syntax.........: _GUICtrlVLC_SetVolume($vlc, $level)
  382. ; Parameters ....: $vlc - The control identifier (controlID) as returned by _GUICtrlVLC_Create.
  383. ; $level - a value between [0-200] which indicates a percentage of the volume.
  384. ; Return values .: On Success - Returns True.
  385. ; On Failure - Returns False.
  386. ; Author ........: seangriffin
  387. ; Modified.......:
  388. ; Remarks .......:
  389. ; Related .......:
  390. ; Link ..........:
  391. ; Example .......: Yes
  392. ;
  393. ; ;==========================================================================================
  394. Func _GUICtrlVLC_SetVolume($vlc, $level)
  395. if IsObj($vlc) = False Then Return False
  396. $vlc.audio.volume = $level
  397. Return True
  398. EndFunc
  399. ; #FUNCTION# ;===============================================================================
  400. ;
  401. ; Name...........: _VLCErrorHandlerRegister()
  402. ; Description ...: Register and enable a VLC ActiveX error handler.
  403. ; Syntax.........: _VLCErrorHandlerRegister($s_functionName = "__VLCInternalErrorHandler")
  404. ; Parameters ....: $s_functionName - The name of the AutoIT function to run if an error occurs.
  405. ; Return values .: On Success - Returns 1
  406. ; On Failure - Returns 0
  407. ; Author ........: seangriffin
  408. ; Modified.......:
  409. ; Remarks .......:
  410. ; Related .......:
  411. ; Link ..........:
  412. ; Example .......: Yes
  413. ;
  414. ; ;==========================================================================================
  415. Func _VLCErrorHandlerRegister($s_functionName = "__VLCInternalErrorHandler")
  416. _IEErrorNotify(false)
  417. $sVLCUserErrorHandler = $s_functionName
  418. $oVLCErrorHandler = ""
  419. $oVLCErrorHandler = ObjEvent("AutoIt.Error", $s_functionName)
  420. If IsObj($oVLCErrorHandler) Then
  421. SetError(0)
  422. Return 1
  423. Else
  424. SetError(0, 1)
  425. Return 0
  426. EndIf
  427. EndFunc
  428. ; #FUNCTION# ;===============================================================================
  429. ;
  430. ; Name...........: __VLCInternalErrorHandler()
  431. ; Description ...: A VLC ActiveX error handler.
  432. ; Syntax.........: __VLCInternalErrorHandler()
  433. ; Parameters ....:
  434. ; Return values .: On Success - Returns 1
  435. ; On Failure - Returns 0
  436. ; Author ........: seangriffin
  437. ; Modified.......:
  438. ; Remarks .......: Doesn't do anything really, except catch and set the error values in
  439. ; $oVLCErrorHandler. $oVLCErrorHandler is global, and can be utilised
  440. ; in the calling script instead.
  441. ; Related .......:
  442. ; Link ..........:
  443. ; Example .......: Yes
  444. ;
  445. ; ;==========================================================================================
  446. Func __VLCInternalErrorHandler()
  447. ; if StringInStr($oVLCErrorHandler.WinDescription, "Unknown name") > 0 Then
  448. ; ConsoleWrite("--> COM / ActiveX Error Encountered in " & @ScriptName & @CRLF & _
  449. ; "----> Unknown Active X object. VLC is most likely not installed)." & @CRLF & _
  450. ; " Please reinstall VLC Player and try again" & @CRLF)
  451. ; SetError(1)
  452. ; EndIf
  453. Return
  454. EndFunc

comments powered by Disqus