Advertisement
Guest User

Untitled

a guest
Aug 5th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package src.standard
  2. {
  3.     import flash.events.*;
  4.     import flash.media.*;
  5.     import flash.net.*;
  6.     import src.global.*;
  7.     import fl.video.*;
  8.    
  9.     public class Box2Video extends Box2
  10.     {
  11.         var showClose:Boolean;
  12.         public var paused:Boolean;
  13.         var currentSeekInterval:int;
  14.         public var ns:NetStream;
  15.         public var duration:Number;
  16.        
  17.         var w:int;
  18.         var h:int;
  19.        
  20.         public function Box2Video(w:Number, h:Number, url:String = null, loop:Boolean = false, showClose:Boolean = true)
  21.         {
  22.             this.w = w;
  23.             this.h = h;
  24.             var myVideo:Video = new Video();
  25.             myVideo.smoothing = true;
  26.            
  27.             var nc:NetConnection = new NetConnection();
  28.             nc.connect(null);
  29.             ns = new NetStream(nc);
  30.             myVideo.attachNetStream(ns);
  31.            
  32.             var client:Object = new Object();
  33.             client.onCuePoint = cuePointHandler;
  34.             client.onMetaData = metaDataHandler;
  35.             ns.client = client;
  36.             ns.addEventListener(NetStatusEvent.NET_STATUS, function(e:NetStatusEvent)
  37.             {
  38.                 Console.log("Video status");
  39.                 for (var str:String in e.info)
  40.                 {
  41.                     Console.log("  " + str + ": " + e.info[str]);
  42.                 }
  43.                 if (e.info.code == "NetStream.Play.Stop")
  44.                     videoEnd();
  45.             });
  46.            
  47.             function cuePointHandler(infoObject:Object):void
  48.             {
  49.                 Console.log("Cue Point");
  50.                 for (var str:String in infoObject)
  51.                     Console.log("  " + str + ": " + infoObject[str]);
  52.             }
  53.            
  54.             function metaDataHandler(infoObject:Object):void
  55.             {
  56.                 Console.log("Meta Data");
  57.                 for (var str:String in infoObject)
  58.                     Console.log("  " + str + ": " + infoObject[str]);
  59.             }
  60.            
  61.             ns.play(url);
  62.             addChild(myVideo);
  63.            
  64.             setChildIndex(myVideo, 0);
  65.             addEventListener(Event.ADDED_TO_STAGE, function(e:Event)
  66.             {
  67.                 myVideo.width = w;
  68.                 myVideo.height = h;
  69.                 Console.log("Video init: width= " + w + ", height= " + h);
  70.             });
  71.         }
  72.        
  73.         public function getPlayheadPercentage()
  74.         {
  75.             return ns.time / duration;
  76.         }
  77.        
  78.         public function videoEnd()
  79.         {
  80.             dispatchEvent(new Event(Event.COMPLETE));
  81.         }
  82.        
  83.         public function show()
  84.         {
  85.             visible = true;
  86.         }
  87.        
  88.         public function hide()
  89.         {
  90.             // Stop the player
  91.             visible = false;
  92.         }
  93.        
  94.         public function flvScrub(n:Number)
  95.         {
  96.             //trace("scrub=" + n);
  97.             ns.seek(n * duration);
  98.             return "";
  99.         }
  100.        
  101.         public function flvPlay(urlIn:String = "")
  102.         {
  103.             paused = false;
  104.             if (urlIn != "")
  105.             {
  106.                 ns.play(urlIn);
  107.             }
  108.             else
  109.             {
  110.                 ns.resume();
  111.             }
  112.         }
  113.        
  114.         public function flvPause()
  115.         {
  116.             paused = true;
  117.             ns.pause();
  118.             // Pause player
  119.         }
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement