If you have "controls" enabled (set to 1) in the URL, by clicking in the video area you can start and pause the video, control the volume, etc. You then exit the program by clicking on the control bar at the bottom of the screen. Or, you can disable "controls" (set to 0) in the URL if you don't need the controls.
I have it set to play full screen but you can tailor this to suit. The next thing it can use is a better way of entering the YouTube video URL.
Suggestions for improvements welcome.
Code: Select all
Enumeration
#MainWindow
#WebGadget
EndEnumeration
ExamineDesktops()
nWidth = DesktopWidth(0)
nHeight = DesktopHeight(0)
;WebAddress.s = "https://www.youtube.com/embed/OALyNX4IbBI?autoplay=1&showinfo=0&controls=1"
;URL$ = "https://www.youtube.com/embed/lGbF_F_i0cY?autoplay=1&showinfo=0&controls=1&rel=0"
webAddress.s = "https://www.youtube.com/embed/lGbF_F_i0cY?autoplay=1&showinfo=0&controls=0&rel=0"
HTML.s = "<html>" + #LF$ +
#TAB$ + "<head>" + #LF$ +
#TAB$ + #TAB$ + "<style type='text/css'>" + #LF$ +
#TAB$ + #TAB$ + #TAB$ + "body {margin-left: 0px; margin-right:0px; margin-top:0px; margin-bottom:0px; overflow: hidden}" + #LF$ +
#TAB$ + #TAB$ + "</style>" + #LF$ +
#TAB$ + "</head>" + #LF$ +
#TAB$ + "<body scroll='no'>" + #LF$ +
#TAB$ + #TAB$ + "<iframe width='" + Str(nWidth) + "' height='" + Str(nHeight) + "' src='" + WebAddress + "' frameborder='0'></iframe>" + #LF$ +
#TAB$ + "</body>" + #LF$ +
"</html>"
lpValueName.s = GetFilePart(ProgramFilename()) : lpData = 11001
If RegCreateKeyEx_(#HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", 0, #Null, #REG_OPTION_VOLATILE, #KEY_ALL_ACCESS, #Null, @phkResult, @lpdwDisposition) = #ERROR_SUCCESS
RegSetValueEx_(phkResult, lpValueName, 0, #REG_DWORD, @lpData, SizeOf(LONG))
RegCloseKey_(phkResult)
If OpenWindow(#MainWindow, 0, 0, nWidth, nHeight, "WebGadget: YouTube",#PB_Window_BorderLess)
AddKeyboardShortcut(#MainWindow, #PB_Shortcut_Escape, 27);ESC TO QUIT
WebGadget(#WebGadget, 0, 0, nWidth, nHeight, #Null$)
SetGadgetAttribute(#WebGadget, #PB_Web_BlockPopupMenu, #True)
SetGadgetAttribute(#WebGadget, #PB_Web_BlockPopups, #True)
WebBrowser2.IWebBrowser2 = GetWindowLongPtr_(GadgetID(#WebGadget), #GWL_USERDATA)
WebBrowser2\put_Silent(#True)
SetGadgetItemText(#WebGadget, #PB_Web_HtmlCode, HTML)
Repeat ;: Until WaitWindowEvent() = #PB_Event_CloseWindow
event = WaitWindowEvent(20)
If event = #PB_Event_Menu ;KEYBOARD INPUT
menuItem = EventMenu()
Select menuItem
Case 27:CloseWindow(#MainWindow): End
EndSelect
EndIf
ForEver
EndIf
If RegOpenKeyEx_(#HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", 0, #KEY_SET_VALUE, @phkResult) = #ERROR_SUCCESS
RegDeleteValue_(phkResult, lpValueName)
RegCloseKey_(phkResult)
EndIf : End
Else
MessageRequester("WebGadget: YouTube", "Registry update failed." + #LF$ + #LF$ + "Operation cancelled.", #MB_ICONERROR)
EndIf