Jump to content

Embedded Video Player


Go to solution Solved by CodingCody37,

Recommended Posts

Hi, I need to embed a video player in my application, I found some stuff in here (VLC.au3, xVideo.dll udf...) but it looks like everything is outdated, since years.

The most recent thread I found is this :

'?do=embed' frameborder='0' data-embedContent>>

with someone having an issue with wmp.au3 udf..which dates from 2006... But apparently he's able to make it work.

When I try running this script, (i'm using latest autoit on Windows 8), I mean, this one :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
 
Global $width = 800
Global $height = 450
Global $IEControl; = null;
Global $MyGUI = GUICreate("WMPlayer Control", $width,$height,(@DesktopWidth-$width)/2,(@DesktopHeight-$height)/2, $WS_OVERLAPPEDWINDOW)
 
Global $oIE = _GUICtrl_CreateWMPlayer("about:blank", 0, 0, $width, $height)
GUISetState (@SW_SHOW, $MyGUI)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
 
Global $playerOBJ = _IEGetObjById($oIE, "objWMPlayer")
if NOT IsObj($playerOBJ) Then
    MsgBox(0, "Error", "WMP failed to be created.");
    Exit;
EndIf
;~ $FileOpen = "C:\Users\Public\Videos\Sample Videos\Wildlife.wmv";
$FileOpen = FileOpenDialog("Open Videos", @UserProfileDir, "Movies (*.3gp;*.mp4;*.avi;*.wmv;*.flv)")
If Not @error Then
    _wmpvalue($playerOBJ, "nocontrols")
    _wmploadmedia($playerOBJ,$FileOpen)
    $mediaName = _wmpvalue($playerOBJ, "getname");
    WinSetTitle($MyGUI, "", "Playing video: " & $mediaName)
Else
    Exit;
EndIf
 
While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit;
    EndSwitch
WEnd
 
Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
    Local $xClient, $yClient
    $xClient = BitAND($ilParam, 0x0000FFFF)
    $yClient = BitShift($ilParam, 16)
    GUICtrlSetPos($IEControl, 0, 0, $xClient, $yClient)
    if NOT @error Then
        if IsObj($playerOBJ) Then $playerOBJ.width = $xClient;
        if IsObj($playerOBJ) Then $playerOBJ.height = $yClient;
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc
 
;===============================================
;===============================================
;===============================================
 
#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(1)
    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 = false, $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 ()
    $IEControl = 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-ms-wmp">' _
                & @CR & '<PARAM NAME="allowHideControls" VALUE="true">' _
                & @CR & '<PARAM NAME="autoStart" VALUE="false">' _
                & @CR & '<PARAM NAME="audioStream" VALUE="false">' _
                & @CR & '<PARAM NAME="autoSize" VALUE="false">' _
                & @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
 
Func _wmpvalue( $object, $setting, $para=1 )
    Switch $setting
        Case "play"
            If $object.controls.isAvailable("play") Then $object.controls.play()
        case "stop"
            If $object.controls.isAvailable("stop") Then $object.controls.stop()
        case "pause"
            If $object.controls.isAvailable("pause") Then $object.controls.pause()
        case "invisible"
            $object.uiMode = "invisible"
        case "controls"
            $object.uiMode = "full"
        case "nocontrols"
            $object.uiMode = "none"
        case "fullscreen"
            $object.fullscreen = "True"
        Case "step"
            If $object.controls.isAvailable("step") Then $object.controls.step($para)
        Case "fastForward"
            If $object.controls.isAvailable("fastForward") Then $object.controls.fastForward()
        Case "fastReverse"
            If $object.controls.isAvailable("fastReverse") Then $object.controls.fastReverse()
        Case "volume"
            $object.settings.volume = $para
        Case "rate"
            $object.settings.rate = $para
        Case "playcount"
            $object.settings.playCount = $para
        Case "setposition"
            $object.controls.currentPosition = $para
        Case "getposition"
            Return $object.controls.currentPosition
        Case "getpositionstring"
            Return $object.controls.currentPositionString
        Case "getduration"
            Return $object.currentMedia.duration
        Case "getname"
            Return $object.currentMedia.name
    EndSwitch
EndFunc

I'm getting an error on line 181 :

If $object.controls.isAvailable("step") Then $object.controls.step($para)

(181,75) : error: missing separator character before keyword

and the cursor is placed after the dot before step($para)

Could anyone explain me what does this error mean, why do I get it while others don't ?

And if anyone has a better idea or has already done it, to embed a video (f4v files, but at least if I could play any other I'd be glad because for the moment I couldn't do it with any video file type with any UDF I tried)

Thanks

Edited by CodingCody37
Link to comment
Share on other sites

  • Solution

I corrected the bug, I don't know the reason behind it, maybe latest autoit are more strict than before, the fact is the 'step' is a keyword, as in  'For $i = 0 to 100 step 10' I believe... and that was making the interpreter crying, the answer was to use Eval :

            If $object.controls.isAvailable("step") Then Eval('object.controls.step($para)')
Link to comment
Share on other sites

  • Moderators

CodingCody37,

That is only trancexx's personal opinion - I and many others, on the other hand, believe Au3Check to be valuable tool to prevent basic coding errors. Admittedly the utility can have problems with some of the more esoteric AutoIt syntax, but if you point out the problem to those who maintain it (Jos and jpm), it can often be fixed. Overall it is a good thing to have in your tool box, as long as you realise it, along with most things, is not infallible. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Developers

....but if you point out the problem to those who maintain it (Jos and jpm), it can often be fixed.

 

This should be fixed already in the Beta version.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks @Jos 

mLipok

Signature beginning:
* Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
* ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * 

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors  * HTML editor * 

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

Yep, it's obvious absolutely nothing can be perfect. I was far from guessing where was this error coming from though, thanks to trancexxx I understood now, and if something similar comes up to me another day after checking my code thoroughly I'll be able to think of this solution too, obviously not for this particular interpretation that bothered me today since Jos will fix it (or, has already in the Beta if I get it.. but i'm using the stable release) :-) Thanks.

(and on-topic, that wmp.au3 udf is exactly what I needed ! back to coding ^^)

Edited by CodingCody37
Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...