For now, it supports youtube and dailymotion. Other plattforms can be added easily.
Note: Music taste might vary!

Code: Select all
; --------------------------------------------------------------------------------
; WebVideoGadget
; --------------------------------------------------------------------------------
; Compiler Pb 5.20 LTS
; Author Karellen (Pb forums)
; License Public domain, use at your own risk
; Version 0.1.0 - initial release
; --------------------------------------------------------------------------------
;
; Syntax: Result = WebVideoGadget(#Gadget,x,y,Width,Height,URL$,[Flags])
;
;
; Description: Displays a streaming video from internet services such as youtube.
; currently supported hosters are: Youtube, Dailymotion
;
;
; Parameters: #Gadget A number to identify the new gadget.
; #PB_Any can be used to auto-generate this number.
;
; x,y, The position and dimension of the new gadget.
; Width,
; Height
;
; URL$ The browser url of the video. Just copy from your browser.
;
; Flags (youtube only)
;
; #WVG_ShowRelated show suggested videos at the end
; #WVG_AutoPlay starts playback automatically
; #WVG_Loop enables loop playback
;
;
; Return value Returns nonzero on success and zero on failure. If #PB_Any was
; used as the #Gadget parameter then the Return-value is the
; auto-generated gadget number on success.
;
;
; Remarks A webgadget is used to display the video, so gadget control
; and event handling for the WebVideoGadget works similar.
;
; Legal note: Keep in mind, that embedding third party content
; to your application might cause license problems. This gadget
; gives you just the technical possibility to embed videos.
; Any legal matters, like copyright issues, are untouched!
;
;
; Example Simple example:
;
; If Openwindow(0,0,0,640,480,"WebVideoGadget")
; WebVideoGadget(0,0,0,640,480,"http://www.youtube.com/watch?v=a8EMT01oSGw")
; Endif
;
; Repeat : Until WaitWindowEvent() = #PB_Event_Closewindow
;
; See bottom of file for a more advanced example. Just run this
; file from the Pb ide. When you include this file the example
; code will be ignored by the compiler
;
;
; See also WebGadget()
;
;
; Supported OS Windows only, because SetGadgetItemText with #PB_Web_HtmlCode
; is just supported on Windows :(
;
; --------------------------------------------------------------------------------
#WVG_ShowRelated = 1
#WVG_AutoPlay = 2
#WVG_Loop = 4
Procedure WebVideoGadget(id.l, x.l, y.l, width.l, height.l, videoUrl.s, flags.l = 0)
Protected html.s, position.l, flag.s, result.l
; create common html code
html = "<html><body scroll=no>" +
"<head><style type="+#DQUOTE$+"text/css"+#DQUOTE$+">" +
"body { margin-left: 0px; margin-right:0px; margin-top:0px; margin-bottom:0px }" +
"</style></head><body>" +
"<iframe width="+#DQUOTE$+width+#DQUOTE$ + " height="+#DQUOTE$+height+#DQUOTE$ +
" frameborder="+#DQUOTE$+"0"+#DQUOTE$ + " allowfullscreen"
; create hoster specific html code
; youtube
If FindString(videoUrl.s,"youtube.com")
position = FindString(videoUrl,"watch?v=")
If position
videoUrl.s = RemoveString(videoUrl, Left(videoUrl,position+7))
EndIf
position = FindString(videoUrl,"/embed/")
If position
videoUrl.s = RemoveString(videoUrl, Left(videoUrl,position+6))
EndIf
position = FindString(videoUrl,"&")
If position
videoUrl.s = Left(videoUrl,position-1)
EndIf
videoUrl = "http://www.youtube.com/embed/"+videoUrl
flag.s = ""
If flags >= #WVG_Loop
flag.s + "loop=1"
flags-#WVG_Loop
EndIf
If flags >= #WVG_AutoPlay
If flag.s <> ""
flag.s + "&"
EndIf
flag.s + "autoplay=1"
flags-#WVG_AutoPlay
EndIf
If flags >= #WVG_ShowRelated
If flag.s <> ""
flag.s + "&"
EndIf
flag.s + "rel=0"
flags-#WVG_ShowRelated
EndIf
videoUrl.s + "?" + flag.s
; dailymotion
ElseIf FindString(videoUrl.s,"dailymotion.com")
position = FindString(videoUrl.s,"#video=")
If position
videoUrl.s = RemoveString(videoUrl, Left(videoUrl,position+6))
EndIf
position = FindString(videoUrl.s,"/video/")
If position
videoUrl.s = RemoveString(videoUrl, Left(videoUrl,position+6))
EndIf
position = FindString(videoUrl,"_")
If position
videoUrl.s = Left(videoUrl,position-1)
EndIf
videoUrl = "http://www.dailymotion.com/embed/video/"+videoUrl
EndIf
; complete the html code
html + " src="+#DQUOTE$+videoUrl+#DQUOTE$ + ">" +
"</iframe></body></html>"
result.l = WebGadget(id,x,y,width,height,"")
If result.l
SetGadgetItemText(id, #PB_Web_HtmlCode, html.s)
EndIf
ProcedureReturn result.l
EndProcedure
; --------------------------------------------------------------------------------
; EXAMPLE
; --------------------------------------------------------------------------------
; Due to the compilerif command this code will be ignored by the compiler
; when you include this file in your application.
; --------------------------------------------------------------------------------
CompilerIf #PB_Compiler_IsMainFile
If OpenWindow(0,0,0,730,400,
"WebVideoGadget - Select video from list by double click",
#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
FrameGadget(0,10,10,200,320,"Videos")
ListViewGadget(1,20,40,180,270)
AddGadgetItem(1,-1,"Phone ad")
AddGadgetItem(1,-1,"Some news")
AddGadgetItem(1,-1,"Good old music :)")
AddGadgetItem(1,-1,"Movie trailer")
AddGadgetItem(1,-1,"Simpsons")
AddGadgetItem(1,-1,"Best english ever!")
FrameGadget(2,220,10,500,320,"Display")
WebVideoGadget(3,230,40,480,270, "")
FrameGadget(4,10,340,710,50,"")
TextGadget(5,20,362,700,30,"Double click a video from the list or enter an url here:")
StringGadget(6,280,357,340,22,"")
ButtonGadget(7,630,355,80,25,"Watch")
EndIf
Repeat
event = WaitWindowEvent()
gadget = EventGadget()
Select event
Case #PB_Event_CloseWindow : End
Case #PB_Event_Gadget
If gadget=1 And EventType()=#PB_EventType_LeftDoubleClick
Select GetGadgetState(1)
Case 0 : WebVideoGadget(3,230,40,480,270, "http://www.youtube.com/watch?v=9-nezImUP0w")
Case 1 : WebVideoGadget(3,230,40,480,270, "http://www.dailymotion.com/video/x15nmoo_two-americans-and-a-german-share-nobel-prize-for-medicine_news")
Case 2 : WebVideoGadget(3,230,40,480,270, "http://www.youtube.com/watch?v=1ljgzwZbxN0")
Case 3 : WebVideoGadget(3,230,40,480,270, "http://www.dailymotion.com/video/x12csnp_gravity-i-ve-got-you-trailer_shortfilms")
Case 4 : WebVideoGadget(3,230,40,480,270, "http://www.dailymotion.com/video/x15l30f_simpsons-treehouse-of-horror-xxiv-references_shortfilms")
Case 5 : WebVideoGadget(3,230,40,480,270, "http://www.youtube.com/watch?v=AhmCgAV2aSA")
EndSelect
ElseIf gadget=7
WebVideoGadget(3,230,40,480,270, GetGadgetText(6))
EndIf
EndSelect
ForEver
CompilerEndIf