-
-
Save PrimaryFeather/19fa9fd0c2fcb0b44fd088411c84d274 to your computer and use it in GitHub Desktop.
Example video playback in Starling.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package starling | |
{ | |
import flash.events.AsyncErrorEvent; | |
import flash.events.NetStatusEvent; | |
import flash.events.VideoTextureEvent; | |
import flash.external.ExternalInterface; | |
import flash.net.NetConnection; | |
import flash.net.NetStream; | |
import starling.display.Image; | |
import starling.display.Sprite; | |
import starling.textures.Texture; | |
public class VideoExperiments extends Sprite | |
{ | |
private static const VIDEO_URL:String = "https://gamua.com/media/starling/demos/video/loop.mp4"; | |
public function VideoExperiments() | |
{ | |
init(); | |
} | |
private function init():void | |
{ | |
log("loading video from " + VIDEO_URL); | |
var nc:NetConnection = new NetConnection(); | |
nc.connect(null); | |
var ns:NetStream = new NetStream(nc); | |
ns.client = { onMetaData: onMetaData, onPlayStatus: onPlayStatus }; | |
ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); | |
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError); | |
var texture:Texture = Texture.fromNetStream(ns, 1, function():void | |
{ | |
addChild(new Image(texture)); | |
}); | |
ns.play(VIDEO_URL); | |
texture.base.addEventListener(VideoTextureEvent.RENDER_STATE, onRenderState); | |
function onRenderState(event:VideoTextureEvent):void | |
{ | |
log("onRenderState: ", event.status); | |
} | |
function onNetStatus(event:NetStatusEvent):void | |
{ | |
log("onNetStatus:", event.info.code); | |
if (event.info.code == "NetStream.Play.Stop") | |
{ | |
ns.seek(0); | |
ns.resume(); | |
} | |
} | |
function onAsyncError(event:AsyncErrorEvent):void | |
{ | |
log("onAsyncError:", event); | |
} | |
function onMetaData(data:Object):void | |
{ | |
log("onMetaData: width = " + data["width"] + ", height = " + data["height"]); | |
} | |
function onPlayStatus(data:Object):void | |
{ | |
log("onPlayStatus:", data.code); | |
} | |
} | |
private static function log(...args):void | |
{ | |
trace.apply(null, args); | |
callExternalInterface("addLog", args.join(" ")); | |
} | |
private static function callExternalInterface(method:String, ...args):void | |
{ | |
if (ExternalInterface.available) | |
{ | |
args.unshift(method); | |
ExternalInterface.call.apply(null, args); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment