void GetDisplayedContent(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
// Check the number of arguments passed.
if (args.Length() < 2) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong number of arguments:this function takes 2 arguments!")));
return;
}
// Check the argument types
if (!args[0]->IsString() || !args[1]->IsFunction()) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong argument types")));
return;
}
//Perform the operation
/*
PlayInfo[0]:当前播放的节目表的驱动器编号;(SD or Flash or RAM)
PlayInfo[1]:当前播放的第00套-第99套节目的索引号,从0开始编号;P00~P99
PlayInfo[2]:当前播放的PLAYLIST.LY文件中的第几个节目,从0开始编号;
PlayInfo[3]:区域1正在播放的节目项索引,从0开始编号
PlayInfo[4]:区域2正在播放的节目项索引,从0开始编号
PlayInfo[5]:区域3正在播放的节目项索引,从0开始编号
PlayInfo[6]:区域4正在播放的节目项索引,从0开始编号
*/
char playInfo[7];
int retVal = SCL_GetPlayInfo(mDevID, (BYTE*)playInfo);
if (!retVal) {
SCL_Close(mDevID);
printf("%c:\\P%02d\\PLAYLIST.LY\n", 1 + 65, 3);
Local<Function> cb = Local<Function>::Cast(args[1]);
const int argc = 1;
Local<Value> argv[argc] = { String::NewFromUtf8(isolate,"SCL_GetPlayInfo failed") };
cb->Call(Null(isolate), argc, argv);
return;
}
//根据 PlayInfo 获取到正在显示得播放列表路径
//驱动器编号
int driveNo = playInfo[0];
printf("%c:\\P%02d\\PLAYLIST.LY\n", playInfo[0] + 65, playInfo[1]);
//文件名称
char dir[30];
sprintf(dir, "P%02d\\PLAYLIST.LY", playInfo[1]);
//当前正在播放节目的编号
int playIndex = playInfo[2];
//下载播放列表
retVal = SCL_ReceiveFile(mDevID, driveNo, dir, "PLAYLIST.LY");
if (!retVal) {
SCL_Close(mDevID);
Local<Function> cb = Local<Function>::Cast(args[1]);
const int argc = 1;
Local<Value> argv[argc] = { String::NewFromUtf8(isolate,"SCL_ReceiveFile failed") };
cb->Call(Null(isolate), argc, argv);
return;
}
SCL_Close(mDevID);
//读取PLAYLIST.LY,取到第playIndex项
//解析显示内容
//将读取到的项返回到javascript
//创建数组
Local<Array> arr = Array::New(isolate, 7);
for (int i = 0; i != 7; i++) {
arr->Set(i, v8::Int32::New(isolate, i));
}
Local<Function> cb = Local<Function>::Cast(args[1]);
const int argc = 2;
Local<Value> argv[argc] = { Null(isolate),arr };
cb->Call(Null(isolate), argc, argv);
return;
}
Node.js Addon 返回数组
最新推荐文章于 2024-08-09 07:32:13 发布