Originally posted by MadGypsy
View Post

package { import flash.media.Video; import flash.filesystem.File; import flash.utils.ByteArray; import flash.desktop.NativeProcess; import flash.desktop.NativeProcessStartupInfo; import flash.net.NetConnection; import flash.net.NetStream; import flash.events.ProgressEvent; import flash.events.NetStatusEvent; /** * ... * @author OneMadGypsy */ public class PlayVideo { private static var _ffmpeg:File; private static var _video:Video; private static var _path:String; private static var _nConn:NetConnection; private static var _nStream:NetStream; private static var _nProcess:NativeProcess; private static var _ready:Function; public static function play(video:Video, path:String, cb:Function):void { _video = video; _path = path; _ready = cb; _ffmpeg = File.applicationDirectory; _ffmpeg.nativePath = dataDirectory() + "\\ffmpeg\\bin\\ffmpeg.exe"; if (NativeProcess.isSupported) { _nConn = new NetConnection(); _nConn.addEventListener(NetStatusEvent.NET_STATUS, statusHandler); _nConn.connect(null); } else throw new Error ("NativeProcess is not supported"); } private static function statusHandler(event:NetStatusEvent):void { switch(event.info.code) { case "NetConnection.Connect.Success": launch(); } } private static function launch():void { _nStream = new NetStream(_nConn); _nStream.client = new CustomClient(_ready); //_nStream.client = {}; _video.attachNetStream(_nStream); _nStream.play(null); var processes:Vector.<String> = new <String>["-i", _path, "-b:v", "4800k", "-ar", "44100", "-ac", "2", "-f", "flv", "-"]; var npInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo(); npInfo.executable = _ffmpeg; npInfo.arguments = processes; _nProcess = new NativeProcess(); _nProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutput); _nProcess.start(npInfo); } private static function onOutput(event:ProgressEvent):void { var bytes:ByteArray = new ByteArray(); _nProcess.standardOutput.readBytes(bytes, 0, _nProcess.standardOutput.bytesAvailable); _nStream.appendBytes(bytes); } private static function dataDirectory():String { var dir:String = File.applicationDirectory.resolvePath('QuakeTasticScreens.swf').nativePath; dir = dir.substr(0, dir.lastIndexOf("\\")); //chop dir = dir.substr(0, dir.lastIndexOf("\\")); //chop return dir; } } } class CustomClient { private var _callback:Function; public function CustomClient(cb:Function):void { _callback = cb; } public function onMetaData(info:Object):void { _callback.call({}, info); } }
Comment