Android Question WebView object and YouTube video

Shahid Saeed

Active Member
Licensed User
Longtime User
You Will need to use WebViewExtra and Youtube API to view the video.

B4A Code:-

B4X:
Sub Globals
    
    Dim www As WebView
    Dim wvxtra As WebViewExtras
    Dim YouTubePlayer As YouTubeStandalonePlayer
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    Activity.LoadLayout("main")

    wvxtra.addJavascriptInterface(www,"B4A")    
    www.LoadURL("http://www.domain.com/videos.html")     

End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub YouTube(videoID As String)
    YouTubePlayer.Initialize("YouTubePlayer")
    If YouTubePlayer.CheckPlayerSupported <> "SUCCESS" Then
        Msgbox("YouTube service not available: " & CRLF & YouTubePlayer.CheckPlayerSupported, "")       
    Else       
        YouTubePlayer.StartVideo("YouTubeDeveloperKey", videoID, 0, True, False)
        
    End If
End Sub

HTML Code:-

B4X:
<a href="javascript:B4A.CallSub('YouTube', true, 'YoutTubeVideoID');">
<img border="0" align="middle" width="150" src="http://img.youtube.com/vi/YouTubeVideoID/hqdefault.jpg">
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
Many thanks for your answer, but the problem is that I can't change html code, it is dowloaded from a site
Sergio
 
Upvote 0
Top