iOS Question Playing YouTube videos

db0070

Active Member
Licensed User
I am using the code below to play a youtube video.
Why does it take so long to load the videos? It appears as if nothing is happening until about 12 seconds later. Is there a better way to play Youtube videos? Is there a flag I can monitor which will indicate that the video has been loaded from the web and is ready to play?

Also, sometimes the first it is called, I do not get the picture, just the sound comes through. The second time it is ok.

I am attaching the cut down version of the program.
B4X:
Sub PlayVideo(videoId As String)
    Dim no As NativeObject = WebView1
    no.RunMethod("setMediaPlaybackRequiresUserAction:", Array(False))
    WebView1.LoadHtml($"<!DOCTYPE html><html>
   <head>
   <style>body{margin:0px 0px 0px 0px;}</style></head>
    <body> <div id="player"></div>
    <script> var tag = document.createElement('script');
    tag.src = "https://www.youtube.com/player_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    var player; function onYouTubePlayerAPIReady()
    { player = new YT.Player('player', { width:'${100%x}', height:'${100%y}', videoId:'${videoId}', events: { 'onReady': onPlayerReady, } }); }
    function onPlayerReady(event) { event.target.playVideo(); }
        </script> </body> </html>"$)
End Sub
 

Attachments

db0070

Active Member
Licensed User
I added Webview1 to a new page, then show that page so now the user see's the video is loading - however long it takes.
 
Top