AdobeAIR使用Javascript,使程序在运行nativeProcess时等待
我试图通过使用nativeProcess运行ffprobe从视频文件中提取元数据。下面的代码对于一个文件的工作原理与它应该的一样,但是在尝试循环遍历一系列文件时会导致错误 我知道问题的原因是Air试图在旧流程完成之前启动新的本地流程。我知道这与收听air.NativeProcessExitEvent.EXIT有关。我就是不能让它工作。如有任何建议,将不胜感激AdobeAIR使用Javascript,使程序在运行nativeProcess时等待,javascript,javascript-events,air,adobe,Javascript,Javascript Events,Air,Adobe,我试图通过使用nativeProcess运行ffprobe从视频文件中提取元数据。下面的代码对于一个文件的工作原理与它应该的一样,但是在尝试循环遍历一系列文件时会导致错误 我知道问题的原因是Air试图在旧流程完成之前启动新的本地流程。我知道这与收听air.NativeProcessExitEvent.EXIT有关。我就是不能让它工作。如有任何建议,将不胜感激 function fileOpen(){ var directory = air.File.userDirectory; tr
function fileOpen(){
var directory = air.File.userDirectory;
try
{
directory.browseForDirectory("Select Directory");
directory.addEventListener(air.Event.SELECT, directorySelected);
}
catch (error)
{
air.trace("Failed:", error.message)
}
function directorySelected(event)
{
directory = event.target ;
var files = directory.getDirectoryListing();
for(i=0; i < files.length; i++){
getMetadata(files[0].nativePath)
//wait here for nativeProcess to finish
}
}
}
function getMetadata(filePathIn){
if(air.NativeProcess.isSupported)
{
}
else
{
air.trace("NativeProcess not supported.");
}
fileIn = filePathIn.toString()
var nativeProcessStartupInfo = new air.NativeProcessStartupInfo();
var file = air.File.applicationStorageDirectory.resolvePath("ffprobe");
nativeProcessStartupInfo.executable = file;
args = new air.Vector["<String>"]();
args.push("-sexagesimal","-show_format","-loglevel","quiet","-show_streams","-print_format","json",filePathIn)
nativeProcessStartupInfo.arguments = args;
process = new air.NativeProcess();
process.start(nativeProcessStartupInfo);
process.addEventListener(air.ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.addEventListener(air.ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
process.addEventListener(air.NativeProcessExitEvent.EXIT, onExit);
process.addEventListener(air.IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
process.addEventListener(air.IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
}
function onOutputData()
{
var fileMetadataJSON = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
air.trace(fileMetadataJSON)
}
function onErrorData(event)
{
air.trace("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable));
}
function onExit(event)
{
air.trace("Process exited with ", event.exitCode);
}
function onIOError(event)
{
air.trace(event.toString());
}
函数fileOpen(){
var directory=air.File.userDirectory;
尝试
{
browseForDirectory(“选择目录”);
directory.addEventListener(air.Event.SELECT,directorySelected);
}
捕获(错误)
{
air.trace(“失败:”,错误消息)
}
已选择功能目录(事件)
{
directory=event.target;
var files=directory.getDirectoryListing();
对于(i=0;i
这里有一个提纲,可以让你知道该怎么做:
- 在
方法中,将局部变量directorySelected()
(数组)升级为成员变量。这将使所选文件的列表可用,以便其他方法可以访问它files
- 删除
方法中的directorySelected()
循环。与其在这里运行循环并尝试运行本机进程,不如调用一个新方法,让我们调用它for
dequeueFileAndRunNativeProcess()
- 这个新的
方法应该检查dequeueFileAndRunNativeProcess()
数组的长度,如果它大于0,它应该files
数组中的第一个文件,并在其上执行本机进程pop()
- 在
方法中,再次调用onExit()
方法dequeueFileAndRunNativeProcess()
文件
数组中没有更多文件时,该过程结束