Версия AutoIt: 3.
Описание:
Требуется вставить видео поток в окно AutoIT.
Видео доступно по адресам: 192.168.1.2/video1.mjpg и rtsp://192.168.1.2/live1.sdp
Предложенные ниже варианты не работают.
Вариант с WMP "зацикливается" авторизации, а вариант с VLC показывает пустое окно.
При запуске непосредственно из проигрывателя VLC видео корректно воспроизводится по обеим ссылкам.
Прошу помощи!
Примечания:
1 вариант:
2 вариант:
Описание:
Требуется вставить видео поток в окно AutoIT.
Видео доступно по адресам: 192.168.1.2/video1.mjpg и rtsp://192.168.1.2/live1.sdp
Предложенные ниже варианты не работают.
Вариант с WMP "зацикливается" авторизации, а вариант с VLC показывает пустое окно.
При запуске непосредственно из проигрывателя VLC видео корректно воспроизводится по обеим ссылкам.
Прошу помощи!
Примечания:
1 вариант:
Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#Region Test
Opt('MustDeclareVars', 1); no required
_IEErrorHandlerRegister (); optional error handler
;Global $movie = FileOpenDialog("Open a movie or playlist", @MyDocumentsDir, "Movies (*.wpl;*.mpg;*.mpeg;*.wmv;*.avi)", 3)
Global $nocontrols=false
Global $url="rtsp://192.168.1.2/live1.sdp"
Global $MyGUI = GUICreate("WMPlayer Control", 430, 250)
Global $but_Station1=GUICtrlCreateButton("Station1",350,5,60,25)
Global $but_Station2=GUICtrlCreateButton("Station2",350,35,60,25)
Global $but_Station3=GUICtrlCreateButton("Station3",350,65,60,25)
Global $StopPlay_But=GUICtrlCreateButton("Stop/Play",350,95,60,25)
Global $FullScreen_But=GUICtrlCreateButton("FullScreen",350,125,60,25)
Global $ControlPanel_ShowHide_But=GUICtrlCreateButton("Hide",350,155,60,25)
Global $oIE = _GUICtrl_CreateWMPlayer($url, 5, 5, 320, 240)
GUISetState (@SW_SHOW, $MyGUI)
Global $playerOBJ = _IEGetObjById($oIE, "objWMPlayer")
While 1
Sleep(10)
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
;
Case $but_Station1
$playerOBJ.controls.stop()
_wmploadmedia($playerOBJ,"rtsp://192.168.1.2/live1.sdp")
;
Case $but_Station2
$playerOBJ.controls.stop()
_wmploadmedia($playerOBJ,"http://192.168.1.2/video1.mjpg")
;
Case $but_Station3
$playerOBJ.controls.stop()
_wmploadmedia($playerOBJ,"http://192.168.1.2/video1.mjpg")
;
Case $StopPlay_But ;остановить, продолжить воспроизведение
If $playerOBJ.controls.isAvailable("play") Then
$playerOBJ.controls.play()
Else
$playerOBJ.controls.stop()
EndIf
;
Case $FullScreen_But ;во весь экран
_wmpvalue( $playerOBJ, "fullscreen")
;
Case $ControlPanel_ShowHide_But ;скрыть показать панель контроля
If $nocontrols==False Then
$nocontrols=True
_wmpvalue( $playerOBJ, "nocontrols")
GUICtrlSetData($ControlPanel_ShowHide_But,"Show")
Else
$nocontrols=False
_wmpvalue( $playerOBJ, "controls")
GUICtrlSetData($ControlPanel_ShowHide_But,"Hide")
EndIf
Endswitch
Wend
$oIE = ""
#EndRegion Test
;===============================================
;===============================================
;===============================================
#cs
_wmploadmedia( $object, $URL )
$object: Object returned from the $playerOBJ = _IEGetObjById($oIE, "objWMPlayer")
$URL: Path or URL of the media
Return: None
#ce
Func _wmploadmedia( $object, $URL)
$object.URL = $URL
While Not $object.controls.isAvailable("play")
Sleep(10)
WEnd
$object.controls.play()
EndFunc
;
;
; Function: _GUICtrl_CreateWMPlayer
; Purpose: Embed Windows Media Player and play one file or one playlist only.
; Notes: PARAM NAME="url" is ReadOnly
; Authors: squirrely1
; borderless IE embed example: GaryFrost
; Kudos - Kare Johansson, CFire
; References:
; http://msdn2.microsoft.com/en-us/library/ms930698.aspx
; http://www.w3schools.com/media/media_playerref.asp
; clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6 - wmplayer latest installed version
; clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95 - wmp 6.4
;===============================================
Func _GUICtrl_CreateWMPlayer($movieURL, $playerLeft, $playerTop, $playerWidth, $playerHeight, _
$insetBorders = 0, $fullscreenMode = False, $showControls = True, $enableContextMenu = True, _
$LoopMode = True, $playCount = 1, $playVolume = 100, $playBalance = 0, $enableFullScreenControls = True)
If $fullscreenMode Then
$fullscreenMode = "true"
Else
$fullscreenMode = "false"
EndIf
If $showControls Then
$showControls = "true"
Else
$showControls = "false"
EndIf
If $enableContextMenu Then
$enableContextMenu = "true"
Else
$enableContextMenu = "false"
EndIf
If $LoopMode Then
$playCount = 999
EndIf
If $enableFullScreenControls Then
$enableFullScreenControls = "true"
Else
$enableFullScreenControls = "false"
EndIf
Local $myIE_Obj = _IECreateEmbedded ()
Local $GUIActiveX = GUICtrlCreateObj($myIE_Obj, $playerLeft, $playerTop, $playerWidth, $playerHeight)
_IENavigate($myIE_Obj, "about:blank")
Local $htmlWMP
$htmlWMP = '' _
& @CR & '<body style="margin:0;padding:0">' _
& @CR & '<OBJECT' _
& @CR & 'ID="objWMPlayer"' _
& @CR & 'STYLE="margin:0;padding:0"' _
& @CR & 'HSPACE="0"' _
& @CR & 'VSPACE="0"' _
& @CR & 'BORDER="0"' _
& @CR & 'WIDTH="' & $playerWidth & '"' _
& @CR & 'HEIGHT="' & $playerHeight & '"' _
& @CR & 'CLASSID="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"' _
& @CR & 'STANDBY="Loading Windows Media Player components..."' _
& @CR & 'TYPE="application/x-oleobject">' _
& @CR & '<PARAM NAME="allowHideControls" VALUE="true">' _
& @CR & '<PARAM NAME="autoStart" VALUE="true">' _
& @CR & '<PARAM NAME="audioStream" VALUE="false">' _
& @CR & '<PARAM NAME="autoSize" VALUE="true">' _
& @CR & '<PARAM NAME="balance" VALUE="' & $playBalance & '"><!-- -100 to 100 -->' _
& @CR & '<!-- <PARAM NAME="bufferingTime" VALUE="5"><!-- seconds -->' _
& @CR & '<PARAM NAME="clickToPlay" VALUE="false"><!-- has no effect -->' _
& @CR & '<PARAM NAME="currentPosition" VALUE="0"><!-- start position within video, in seconds -->' _
& @CR & '<PARAM NAME="enableContextMenu" VALUE="' & $enableContextMenu & '">' _
& @CR & '<PARAM NAME="enableFullScreenControls" VALUE="' & $enableFullScreenControls & '">' _
& @CR & '<PARAM NAME="enabled" VALUE="true"><!-- whether controls are enabled -->' _
& @CR & '<PARAM NAME="fullScreen" VALUE="' & $fullscreenMode & '">' _
& @CR & '<PARAM NAME="mute" VALUE="false">' _
& @CR & '<PARAM NAME="playCount" VALUE="' & $playCount & '">' _
& @CR & '<!-- <PARAM NAME="previewMode" VALUE="true"> -->' _
& @CR & '<PARAM NAME="rate" VALUE="1"><!-- play speed of -.5 to 2 increments of .1 -->' _
& @CR & '<PARAM NAME="sendPlayStateChangeEvents" VALUE="false">' _
& @CR & '<PARAM NAME="showCaptioning" VALUE="false">' _
& @CR & '<PARAM NAME="showControls" VALUE="' & $showControls & '">' _
& @CR & '<PARAM NAME="showGotoBar" VALUE="false">' _
& @CR & '<PARAM NAME="showPositionControls" VALUE="true"><!-- uiMode must = "full" -->' _
& @CR & '<PARAM NAME="showStatusBar" VALUE="false"><!-- has no effect -->' _
& @CR & '<PARAM NAME="showDisplay" VALUE="true"><!-- has no effect - reportedly shows filename -->' _
& @CR & '<PARAM NAME="stretchToFit" VALUE="true">' _
& @CR & '<PARAM NAME="uiMode" VALUE="full"><!-- invisible, none, mini, full -->' _
& @CR & '<!-- <PARAM NAME="videoBorderWidth" VALUE="0"> -->' _
& @CR & '<PARAM NAME="volume" VALUE="' & $playVolume & '"><!-- volume percent setting of wmplayer.exe -->' _
& @CR & '<PARAM NAME="windowlessVideo" VALUE="false"><!-- must be the default (false) for function to work in wmp 9.0, otherwise might renders video directly in the client area -->' _
& @CR & '</OBJECT>' _
& @CR & '</body>'
_IEDocWriteHTML ($myIE_Obj, $htmlWMP)
_IEAction ($myIE_Obj, "refresh")
$myIE_Obj.document.body.scroll = "no"
$myIE_Obj.document.body.style.border = $insetBorders
Return $myIE_Obj
EndFunc ;==>_GUICtrl_CreateWMPlayer
;
;
#cs
_wmpsetvalue( $object, $setting, $para=1 )
$object: Object returned from the _wmpcreate()
$setting: "play"
"stop"
"pause"
"invisible" (Hides all)
"control" (Shows controls)
"nocontrol" (Hides controls)
"fullscreen"
"step" (frames to step before freezing)
"fastforward"
"fastreverse"
"volume" (0 To 100)
"rate" (-10 To 10)
"playcount"
Return: None
#ce
Func _wmpvalue( $object, $setting, $para=1 )
Select
Case $setting = "play"
If $object.controls.isAvailable("play") Then $object.controls.play()
Case $setting = "stop"
If $object.controls.isAvailable("stop") Then $object.controls.stop()
Case $setting = "pause"
If $object.controls.isAvailable("pause") Then $object.controls.pause()
Case $setting = "invisible"
$object.uiMode = "invisible"
Case $setting = "controls"
$object.uiMode = "full"
Case $setting = "nocontrols"
$object.uiMode = "none"
Case $setting = "fullscreen"
$object.fullscreen = "True"
Case $setting = "step"
If $object.controls.isAvailable("step") Then $object.controls.step($para)
Case $setting = "fastForward"
If $object.controls.isAvailable("fastForward") Then $object.controls.fastForward()
Case $setting = "fastReverse"
If $object.controls.isAvailable("fastReverse") Then $object.controls.fastReverse()
Case $setting = "volume"
$object.settings.volume = $para
Case $setting = "rate"
$object.settings.rate = $para
Case $setting = "playcount"
$object.settings.playCount = $para
Case $setting = "setposition"
$object.controls.currentPosition = $para
Case $setting = "getposition"
Return $object.controls.currentPosition
Case $setting = "getpositionstring";Returns HH:MM:SS
Return $object.controls.currentPositionString
Case $setting = "getduration"
Return $object.currentMedia.duration
EndSelect
EndFunc
2 вариант:
Код:
#include <GUIConstants.au3>
#include <VLC.au3>
#include <SliderConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiSlider.au3>
Const $ini_filename = @ScriptDir & "\VLC UDF Example.ini"
Dim $msg, $state = 0
Global $position_slider_drag = False, $vlc1, $position_slider, $user_stop = False, $main_gui, $video_path_input
_VLCErrorHandlerRegister()
; Setup Main GUI
$main_gui = GUICreate("VLC UDF Example", 800, 600, -1, -1)
GUICtrlCreateLabel("Video Path", 10, 10, 60, 20)
$video_path_input = GUICtrlCreateInput(IniRead($ini_filename, "Main", "videopath", ""), 70, 10, 600, 20)
$video_path_button = GUICtrlCreateButton("Select (Insert)", 700, 10, 80, 20)
$vlc1 = _GUICtrlVLC_Create(0, 50, 800, 450)
if $vlc1 = False then
msgbox(0, "VLC UDF Example", "_GUICtrlVLC_Create failed." & @CRLF & _
"The most likely cause is that you don't have VLC installed." & @CRLF & _
"Make sure VLC, and the ActiveX component, is installed.")
Exit
EndIf
$position_slider = GUICtrlCreateSlider(0, 500, 800, 30, $TBS_NOTICKS)
$backward_button = GUICtrlCreateButton("Rewind (Arrow Left)", 10, 535, 120, 20)
GUICtrlSetState($backward_button, $GUI_DISABLE)
$pause_button = GUICtrlCreateButton("Pause (Space)", 160, 535, 80, 20)
GUICtrlSetState($pause_button, $GUI_DISABLE)
$stop_button = GUICtrlCreateButton("Stop", 280, 535, 80, 20)
GUICtrlSetState($stop_button, $GUI_DISABLE)
$play_button = GUICtrlCreateButton("Play", 415, 535, 80, 20)
GUICtrlSetState($play_button, $GUI_DISABLE)
$close_button = GUICtrlCreateButton("Close (Esc)", 550, 535, 80, 20)
$forward_button = GUICtrlCreateButton("FForward (Arrow Right)", 670, 535, 120, 20)
GUICtrlSetState($forward_button, $GUI_DISABLE)
GUICtrlCreateLabel("Video Status", 10, 565, 80, 20)
$status_input = GUICtrlCreateInput("", 75, 565, 20, 20)
GUICtrlCreateLabel("Volume (F6 && F7)", 310, 565, 80, 20)
$volume_slider = GUICtrlCreateSlider(390, 560, 250, 30)
GUICtrlSetLimit($volume_slider, 200)
GUICtrlSetData($volume_slider, _GUICtrlVLC_GetVolume($vlc1))
$volume_up = GUICtrlCreateDummy()
$volume_down = GUICtrlCreateDummy()
$mute_button = GUICtrlCreateButton("Mute (F8)", 670, 565, 120, 20)
dim $main_gui_accel[8][2]=[["{ESC}", $close_button], ["{RIGHT}", $forward_button], ["{LEFT}", $backward_button], [" ", $pause_button], ["{INSERT}", $video_path_button], ["{F6}", $volume_down], ["{F7}", $volume_up], ["{F8}", $mute_button]]
; Show Main GUI
GUISetState(@SW_SHOW)
GUISetAccelerators($main_gui_accel)
; Load last video played
if StringLen(GUICtrlRead($video_path_input)) > 0 Then UpdateGUIAndPlay(GUICtrlRead($video_path_input))
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
if StringLen(GUICtrlRead($video_path_input)) > 0 Then $state = _GUICtrlVLC_GetState($vlc1)
if $state = 3 Then GUICtrlSetState($play_button, $GUI_DISABLE)
; Main Loop
while 1
; Get the video state
if StringLen(GUICtrlRead($video_path_input)) > 0 Then
$state = _GUICtrlVLC_GetState($vlc1)
GUICtrlSetData($status_input, $state)
EndIf
; Loop a finished video
if $state = 6 and $user_stop = False Then UpdateGUIAndPlay()
; Update the video position slider
if ($state = 3 or $state = 4) and $position_slider_drag = False Then
GUICtrlSetData($position_slider, (_GUICtrlVLC_GetTime($vlc1) / 1000))
$position_slider_drag = False
EndIf
if $msg = $volume_slider Then
_GUICtrlVLC_SetVolume($vlc1, GUICtrlRead($volume_slider))
EndIf
if $msg = $volume_down Then
$new_vol = _GUICtrlVLC_GetVolume($vlc1) - 10
if $new_vol < 0 then $new_vol = 0
_GUICtrlVLC_SetVolume($vlc1, $new_vol)
GUICtrlSetData($volume_slider, $new_vol)
EndIf
if $msg = $volume_up Then
$new_vol = _GUICtrlVLC_GetVolume($vlc1) + 10
if $new_vol > 200 then $new_vol = 200
_GUICtrlVLC_SetVolume($vlc1, $new_vol)
GUICtrlSetData($volume_slider, $new_vol)
EndIf
if $msg = $mute_button Then
if _GUICtrlVLC_GetMute($vlc1) = True Then
_GUICtrlVLC_SetMute($vlc1, False)
Else
_GUICtrlVLC_SetMute($vlc1, True)
EndIf
EndIf
if $msg = $video_path_button Then
$video_path = FileOpenDialog("VLC UDF Example - Select Video", "C:\", "Videos (*.avi;*.flv;*.mp4)", 3)
if StringLen($video_path) > 0 Then UpdateGUIAndPlay($video_path)
EndIf
if $msg = $forward_button Then
_GUICtrlVLC_SeekRelative($vlc1, 5000)
EndIf
If $msg = $backward_button Then
_GUICtrlVLC_SeekRelative($vlc1, -5000)
EndIf
if $msg = $pause_button Then
_GUICtrlVLC_Pause($vlc1)
EndIf
if $msg = $stop_button Then
_GUICtrlVLC_Stop($vlc1)
$user_stop = True
GUICtrlSetState($backward_button, $GUI_DISABLE)
GUICtrlSetState($forward_button, $GUI_DISABLE)
GUICtrlSetState($pause_button, $GUI_DISABLE)
GUICtrlSetState($stop_button, $GUI_DISABLE)
GUICtrlSetState($play_button, $GUI_ENABLE)
EndIf
if $msg = $play_button Then
$user_stop = False
$vlc1.playlist.play()
GUICtrlSetState($backward_button, $GUI_ENABLE)
GUICtrlSetState($forward_button, $GUI_ENABLE)
GUICtrlSetState($pause_button, $GUI_ENABLE)
GUICtrlSetState($stop_button, $GUI_ENABLE)
GUICtrlSetState($play_button, $GUI_DISABLE)
EndIf
If $msg = $GUI_EVENT_CLOSE or $msg = $close_button Then
IniWrite($ini_filename, "Main", "videopath", GUICtrlRead($video_path_input))
ExitLoop
EndIf
$msg = GUIGetMsg()
WEnd
Func UpdateGUIAndPlay($path = "")
GUICtrlSetState($play_button, $GUI_DISABLE)
if StringLen($path) > 0 Then
GUICtrlSetData($video_path_input, $path)
_GUICtrlVLC_Clear($vlc1)
_GUICtrlVLC_Play($vlc1, _GUICtrlVLC_Add($vlc1, GUICtrlRead($video_path_input)))
Else
_GUICtrlVLC_Play($vlc1, 0)
EndIf
While _GUICtrlVLC_GetState($vlc1) <> 3
WEnd
GUICtrlSetLimit($position_slider, (_GUICtrlVLC_GetLength($vlc1) / 1000))
GUICtrlSetData($position_slider, 0)
$position_slider_drag = False
GUICtrlSetState($backward_button, $GUI_ENABLE)
GUICtrlSetState($forward_button, $GUI_ENABLE)
GUICtrlSetState($pause_button, $GUI_ENABLE)
GUICtrlSetState($stop_button, $GUI_ENABLE)
GUICtrlSetState($play_button, $GUI_DISABLE)
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndSlider
$hWndSlider = $position_slider
If Not IsHWnd($position_slider) Then $hWndSlider = GUICtrlGetHandle($position_slider)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndSlider
Switch $iCode
case $NM_CUSTOMDRAW
$position_slider_drag = True
Case $NM_RELEASEDCAPTURE
_GUICtrlVLC_SeekAbsolute($vlc1, (GUICtrlRead($position_slider) * 1000))
$position_slider_drag = False
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc