-
-
Save PrimaryFeather/645a92bbf0a8e6e03b67 to your computer and use it in GitHub Desktop.
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
/** | |
* Created by redge on 12.11.14. | |
*/ | |
package | |
{ | |
import flash.display3D.Context3D; | |
import flash.display3D.Context3DTextureFormat; | |
import flash.display3D.textures.VideoTexture; | |
import flash.events.AsyncErrorEvent; | |
import flash.events.Event; | |
import flash.events.NetStatusEvent; | |
import flash.media.Camera; | |
import flash.net.NetConnection; | |
import flash.net.NetStream; | |
import flash.utils.ByteArray; | |
import starling.core.Starling; | |
import starling.display.Image; | |
import starling.display.Sprite; | |
import starling.textures.ConcreteTexture; | |
public class VideoTextureExperiments extends Sprite | |
{ | |
[Embed(source="../assets/sample.3gp", mimeType = "application/octet-stream")] | |
private static const VideoClip:Class; | |
private var _netConnection:NetConnection; | |
private var _netStream:NetStream; | |
private var _texture:VideoTexture; | |
public function VideoTextureExperiments() | |
{ | |
trace("supports video texture?", Context3D.supportsVideoTexture); | |
initWithCamera(); // -> works! | |
// initWithVideo(); // -> does not work | |
} | |
private function initWithCamera():void | |
{ | |
var camera:Camera = Camera.getCamera(); | |
trace("FPS: " + camera.fps); | |
_texture = Starling.current.context.createVideoTexture(); | |
_texture.addEventListener("renderState", onRenderState); | |
_texture.attachCamera(camera); | |
} | |
private function initWithVideo():void | |
{ | |
_netConnection = new NetConnection(); | |
_netConnection.connect(null); | |
_netStream = new NetStream(_netConnection); | |
_netStream.client = { onMetaData: onMetaData }; | |
_netStream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); | |
_netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError); | |
_texture = Starling.current.context.createVideoTexture(); | |
_texture.attachNetStream(_netStream); | |
_texture.addEventListener("renderState", onRenderState); | |
_netStream.play(null); | |
_netStream.appendBytes(new VideoClip() as ByteArray); | |
trace("Waiting for render state"); | |
function onNetStatus(event:NetStatusEvent):void | |
{ | |
trace(event.info.code); | |
} | |
function onAsyncError(event:AsyncErrorEvent):void | |
{ | |
trace(event); | |
} | |
function onMetaData(metaData:Object):void | |
{ | |
trace("onMetaData"); | |
} | |
} | |
private function onRenderState(event:Event):void | |
{ | |
trace("onRenderState"); | |
var concreteTexture:ConcreteTexture = | |
new ConcreteTexture(_texture, Context3DTextureFormat.BGRA, 512, 512, false, true); | |
var image:Image = new Image(concreteTexture); | |
addChild(image); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment