AS3 Load Youtube Embed

Load Youtube pada AIR Android AS3:

1.Cara I Load Https://youtube.com melalui Navigasi Langsung


var url:String = "https://www.youtube.com/watch?v=IXcbQ_BiGro";
var req:URLRequest = new URLRequest(url);
navigateToURL(req);


2.Cara II EMbeD  Https://youtube.com melalui Navigasi Langsung

var wt:uint;
var ht:uint ;
var webview:StageWebView ;
var rect:Rectangle;
var url:String;


//url="https://www.youtube.com/apiplayer?video_id=tf7gy8j7BqA&autostart=1&autoplay=1&fs=0&controls=0&autohide=1&iv_load_policy=0&rel=0&start=0&showinfo=0&vq=hd720&";
autostart=1&autoplay=1&fs=1&controls=0&autohide=1&iv_load_policy=0&rel=0&start=0&showinfo=0&vq=hd720"; //cara Panjang lengkap


//AIzaSyBQw3ZexsBHWcRf4iHCBGE18rizoy_G9I8//jika gagal load gambar
//"https://www.youtube.com/v/tf7gy8j7BqA"; //ini Untuk HTML4
//url ="http://192.168.1.6/__top2020/youtube/app.php"; ////ini Untuk Via .php

url="https://www.youtube.com/watch?v=tf7gy8j7BqA"; //ini Untuk HTML5

wt = this.stage.stageWidth;
ht = this.stage.stageHeight;
webview = new StageWebView();
rect = new Rectangle(0,0,wt,ht);
webview.stage = this.stage;
webview.viewPort = rect;
webview.loadURL(url);

jika pakai cara via .web tambahkan code app.php sbb

app.php
<!DOCTYPE html>
<html>
  <body>
    <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
    <div id="player"></div>

    <script>
      // 2. This code loads the IFrame Player API code asynchronously.
      var tag = document.createElement('script');

      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      // 3. This function creates an <iframe> (and YouTube player)
      //    after the API code downloads.
      var player;
      function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
          height: '390',
          width: '640',
          videoId: 'tf7gy8j7BqA',
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
          }
        });
      }
//https://www.youtube.com/watch?v=M7lc1UVf-VE
      // 4. The API will call this function when the video player is ready.
      function onPlayerReady(event) {
        event.target.playVideo();
      }

      // 5. The API calls this function when the player's state changes.
      //    The function indicates that when playing a video (state=1),
      //    the player should play for six seconds and then stop.
      var done = false;
      function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.PLAYING && !done) {
          setTimeout(stopVideo, 6000);
          done = true;
        }
      }
      function stopVideo() {
        player.stopVideo();
      }
    </script>
  </body>
</html>

3.Cara III EMbeD  Https://youtube.com melalui Navigasi Langsung

package  {
    import flash.display.MovieClip;
    import flash.media.StageWebView;
    import flash.geom.Rectangle;
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;
    import flash.desktop.NativeApplication;
               
    public class StageWebViewExample extends MovieClip{

        private var webView:StageWebView = new StageWebView();
                               
        public function StageWebViewExample()
        {
            webView.stage = this.stage;
            webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight );
            webView.loadURL( "https://www.youtube.com/watch?v=tf7gy8j7BqA" );
                                               
            stage.addEventListener( KeyboardEvent.KEY_DOWN, onKey );
        }
                               
        private function onKey( event:KeyboardEvent ):void
        {
            if( event.keyCode == Keyboard.BACK && webView.isHistoryBackEnabled )
            {
                trace("Back.");
                webView.historyBack();
                event.preventDefault();
            }

            if( event.keyCode == Keyboard.SEARCH && webView.isHistoryForwardEnabled )
            {
                trace("Forward.");
                webView.historyForward();
            }
        }
    }
}



Comments

Popular posts from this blog

Package AS3

Onclick Trigger