turn videotube into an abstract class so that we can implement the youtube api
This commit is contained in:
parent
c11ccce4ee
commit
eb1974a955
|
@ -44,12 +44,12 @@ package
|
||||||
}
|
}
|
||||||
private function onDrawBegin(e: Event): void
|
private function onDrawBegin(e: Event): void
|
||||||
{
|
{
|
||||||
videotube.stream.pause();
|
videotube.pause();
|
||||||
}
|
}
|
||||||
private function onDrawEnd(e: Event): void
|
private function onDrawEnd(e: Event): void
|
||||||
{
|
{
|
||||||
gamedisc.AddQte(new Qte(sketchShape.rgpoint, videotube.stream.time));
|
gamedisc.AddQte(new Qte(sketchShape.rgpoint, videotube.time()));
|
||||||
videotube.stream.resume();
|
videotube.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,10 @@ package
|
||||||
{
|
{
|
||||||
rgqte.splice(Math.abs(Util.binarySearch(rgqte, qte, Qte.compare)), 0, qte);
|
rgqte.splice(Math.abs(Util.binarySearch(rgqte, qte, Qte.compare)), 0, qte);
|
||||||
}
|
}
|
||||||
|
public function CreateVideotube():Videotube
|
||||||
|
{
|
||||||
|
return new VideotubeFlv(this);
|
||||||
|
}
|
||||||
public function ToJson():Object
|
public function ToJson():Object
|
||||||
{
|
{
|
||||||
var jsonRgqte:Array = [];
|
var jsonRgqte:Array = [];
|
||||||
|
|
|
@ -21,7 +21,7 @@ package
|
||||||
public function Main():void
|
public function Main():void
|
||||||
{
|
{
|
||||||
gamedisc = new Gamedisc("The Last Eichhof - Longplay.flv");
|
gamedisc = new Gamedisc("The Last Eichhof - Longplay.flv");
|
||||||
videotube = new Videotube(gamedisc);
|
videotube = gamedisc.CreateVideotube();
|
||||||
if (stage) init();
|
if (stage) init();
|
||||||
else addEventListener(Event.ADDED_TO_STAGE, init);
|
else addEventListener(Event.ADDED_TO_STAGE, init);
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ package
|
||||||
gameplayer = new GamePlayer(videotube, gamedisc);
|
gameplayer = new GamePlayer(videotube, gamedisc);
|
||||||
addChild(gameplayer);
|
addChild(gameplayer);
|
||||||
}
|
}
|
||||||
videotube.stream.seek(0);
|
videotube.seek(0);
|
||||||
}
|
}
|
||||||
private function onKey(key:KeyboardEvent):void
|
private function onKey(key:KeyboardEvent):void
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,74 +1,19 @@
|
||||||
package
|
package
|
||||||
{
|
{
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import flash.events.Event;
|
import flash.events.EventDispatcher;
|
||||||
import flash.media.Video;
|
|
||||||
import flash.net.NetConnection;
|
|
||||||
import flash.net.NetStream;
|
|
||||||
/**
|
/**
|
||||||
* ...
|
* ...
|
||||||
* @author jjp
|
* @author jjp
|
||||||
*/
|
*/
|
||||||
public class Videotube extends Sprite
|
public class Videotube extends Sprite
|
||||||
{
|
{
|
||||||
private var flv:Video;
|
public function play():void { throw "not implemented"; }
|
||||||
private var gamedisc:Gamedisc;
|
public function pause():void { throw "not implemented"; }
|
||||||
public var stream:NetStream;
|
public function resume():void { throw "not implemented"; }
|
||||||
private var iqte:int;
|
public function time():Number { throw "not implemented"; }
|
||||||
private var secPrev:Number;
|
public function seek(sec:Number):void { throw "not implemented"; }
|
||||||
public function Videotube(gamedisc:Gamedisc)
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
this.gamedisc = gamedisc;
|
|
||||||
iqte = 0;
|
|
||||||
secPrev = 0;
|
|
||||||
addEventListener(Event.ADDED_TO_STAGE, init);
|
|
||||||
}
|
|
||||||
private function init(e: Event):void
|
|
||||||
{
|
|
||||||
removeEventListener(Event.ADDED_TO_STAGE, init);
|
|
||||||
addEventListener(Event.REMOVED_FROM_STAGE, cleanup);
|
|
||||||
|
|
||||||
flv = new Video(stage.stageWidth, stage.stageHeight);
|
|
||||||
addChild(flv);
|
|
||||||
var conn:NetConnection = new NetConnection();
|
|
||||||
conn.connect(null);
|
|
||||||
stream = new NetStream(conn);
|
|
||||||
stream.client = new Object();
|
|
||||||
flv.attachNetStream(stream);
|
|
||||||
|
|
||||||
stage.addEventListener(Event.ENTER_FRAME, tick);
|
|
||||||
}
|
|
||||||
private function cleanup(e: Event):void
|
|
||||||
{
|
|
||||||
removeEventListener(Event.REMOVED_FROM_STAGE, cleanup);
|
|
||||||
stage.removeEventListener(Event.ENTER_FRAME, tick);
|
|
||||||
}
|
|
||||||
private function tick(e: Event):void
|
|
||||||
{
|
|
||||||
var secNow:Number = stream.time;
|
|
||||||
if (secNow > secPrev && secPrev >= 0)
|
|
||||||
{
|
|
||||||
while(iqte < gamedisc.rgqte.length)
|
|
||||||
{
|
|
||||||
var qte:Qte = gamedisc.rgqte[iqte];
|
|
||||||
if (qte.secTrigger > secNow)
|
|
||||||
break;
|
|
||||||
if (qte.secTrigger > secPrev)
|
|
||||||
dispatchEvent(new EventQte(qte));
|
|
||||||
iqte ++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
iqte = 0;
|
|
||||||
}
|
|
||||||
secPrev = secNow;
|
|
||||||
}
|
|
||||||
public function play():void
|
|
||||||
{
|
|
||||||
stream.play(gamedisc.urlVideo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
74
src/VideotubeFlv.as
Normal file
74
src/VideotubeFlv.as
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
package
|
||||||
|
{
|
||||||
|
import flash.display.Sprite;
|
||||||
|
import flash.events.Event;
|
||||||
|
import flash.media.Video;
|
||||||
|
import flash.net.NetConnection;
|
||||||
|
import flash.net.NetStream;
|
||||||
|
/**
|
||||||
|
* ...
|
||||||
|
* @author jjp
|
||||||
|
*/
|
||||||
|
public class VideotubeFlv extends Videotube
|
||||||
|
{
|
||||||
|
private var flv:Video;
|
||||||
|
private var gamedisc:Gamedisc;
|
||||||
|
private var stream:NetStream;
|
||||||
|
private var iqte:int;
|
||||||
|
private var secPrev:Number;
|
||||||
|
public function VideotubeFlv(gamedisc:Gamedisc)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.gamedisc = gamedisc;
|
||||||
|
iqte = 0;
|
||||||
|
secPrev = 0;
|
||||||
|
addEventListener(Event.ADDED_TO_STAGE, init);
|
||||||
|
}
|
||||||
|
private function init(e: Event):void
|
||||||
|
{
|
||||||
|
removeEventListener(Event.ADDED_TO_STAGE, init);
|
||||||
|
addEventListener(Event.REMOVED_FROM_STAGE, cleanup);
|
||||||
|
|
||||||
|
flv = new Video(stage.stageWidth, stage.stageHeight);
|
||||||
|
addChild(flv);
|
||||||
|
var conn:NetConnection = new NetConnection();
|
||||||
|
conn.connect(null);
|
||||||
|
stream = new NetStream(conn);
|
||||||
|
stream.client = new Object();
|
||||||
|
flv.attachNetStream(stream);
|
||||||
|
|
||||||
|
stage.addEventListener(Event.ENTER_FRAME, tick);
|
||||||
|
}
|
||||||
|
private function cleanup(e: Event):void
|
||||||
|
{
|
||||||
|
removeEventListener(Event.REMOVED_FROM_STAGE, cleanup);
|
||||||
|
stage.removeEventListener(Event.ENTER_FRAME, tick);
|
||||||
|
}
|
||||||
|
private function tick(e: Event):void
|
||||||
|
{
|
||||||
|
var secNow:Number = stream.time;
|
||||||
|
if (secNow > secPrev && secPrev >= 0)
|
||||||
|
{
|
||||||
|
while(iqte < gamedisc.rgqte.length)
|
||||||
|
{
|
||||||
|
var qte:Qte = gamedisc.rgqte[iqte];
|
||||||
|
if (qte.secTrigger > secNow)
|
||||||
|
break;
|
||||||
|
if (qte.secTrigger > secPrev)
|
||||||
|
dispatchEvent(new EventQte(qte));
|
||||||
|
iqte ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iqte = 0;
|
||||||
|
}
|
||||||
|
secPrev = secNow;
|
||||||
|
}
|
||||||
|
public override function play():void { stream.play(gamedisc.urlVideo); }
|
||||||
|
public override function pause():void { stream.pause(); }
|
||||||
|
public override function resume():void { stream.resume(); }
|
||||||
|
public override function time():Number { return stream.time; }
|
||||||
|
public override function seek(sec:Number):void { stream.seek(sec); }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue