Skip to content

Commit 15eddfe

Browse files
authored
Merge pull request #40 from VideoOS/dev_2.10.1
Dev 2.10.1
2 parents 98bbfa7 + 269cefb commit 15eddfe

22 files changed

+657
-62
lines changed

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/LuaHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import cn.com.venvy.Platform;
1212
import cn.com.venvy.lua.binder.UIGradientViewBinder;
13+
import cn.com.venvy.lua.binder.VenvyAcrCloudBinder;
1314
import cn.com.venvy.lua.binder.VenvyActivityLifeCycleBinder;
1415
import cn.com.venvy.lua.binder.VenvyAppletBinder;
1516
import cn.com.venvy.lua.binder.VenvyHttpRequestBinder;
@@ -34,6 +35,7 @@ public class LuaHelper {
3435
private static UIGradientViewBinder uiGradientViewBinder;
3536
private static VenvyMediaLifeCycleBinder venvyMediaLifeCycleBinder;
3637
private static VenvyMqttBinder venvyMqttBinder;
38+
private static VenvyAcrCloudBinder acrCloudBinder;
3739
private static VenvyWebViewBinder venvyWebViewBinder;
3840
private static VenvyActivityLifeCycleBinder venvyActivityLifeCycleBinder;
3941
private static VenvyKeyboardBinder venvyKeyboardBinder;
@@ -76,6 +78,7 @@ private static void registerNativeLibs(@NonNull LuaView luaView, Platform platfo
7678
luaView.registerLibs(getUiGradientViewBinder(),
7779
getMediaLifeCycleBinder(platform),
7880
getMqttBinder(),
81+
getAcrCloudBinder(platform),
7982
getAppletBinder(platform),
8083
getSvgaBinder(),
8184
getWebViewBinder(platform),
@@ -123,6 +126,12 @@ private static VenvyMqttBinder getMqttBinder() {
123126
return venvyMqttBinder == null ? venvyMqttBinder = new VenvyMqttBinder() : venvyMqttBinder;
124127
}
125128

129+
private static VenvyAcrCloudBinder getAcrCloudBinder(Platform platform) {
130+
VenvyAcrCloudBinder venvyAcrCloudBinder = acrCloudBinder == null ? acrCloudBinder = new VenvyAcrCloudBinder() : acrCloudBinder;
131+
venvyAcrCloudBinder.setPlatform(platform);
132+
return venvyAcrCloudBinder;
133+
}
134+
126135
private static VenvyAppletBinder getAppletBinder(Platform platform) {
127136
VenvyAppletBinder appletBinder = venvyAppletBinder == null ? venvyAppletBinder = new VenvyAppletBinder() : venvyAppletBinder;
128137
appletBinder.setPlatform(platform);
@@ -156,6 +165,7 @@ public static void destroy() {
156165
venvyWebViewBinder = null;
157166
venvyMediaLifeCycleBinder = null;
158167
venvyMqttBinder = null;
168+
acrCloudBinder = null;
159169
venvyAppletBinder = null;
160170
venvyActivityLifeCycleBinder = null;
161171
venvyKeyboardBinder = null;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package cn.com.venvy.lua.binder;
2+
3+
import com.taobao.luaview.fun.base.BaseFunctionBinder;
4+
import com.taobao.luaview.fun.base.BaseVarArgUICreator;
5+
import com.taobao.luaview.view.interfaces.ILVView;
6+
7+
import org.luaj.vm2.Globals;
8+
import org.luaj.vm2.LuaValue;
9+
import org.luaj.vm2.Varargs;
10+
import org.luaj.vm2.lib.LibFunction;
11+
12+
import cn.com.venvy.Platform;
13+
import cn.com.venvy.lua.maper.VenvyAcrCloudMapper;
14+
import cn.com.venvy.lua.view.VenvyLVAcrClouldCallback;
15+
16+
/**
17+
* Created by mac on 18/3/29.
18+
*/
19+
20+
public class VenvyAcrCloudBinder extends BaseFunctionBinder {
21+
private Platform mPlatform;
22+
23+
public VenvyAcrCloudBinder() {
24+
super("AcrCloud");
25+
}
26+
27+
public void setPlatform(Platform platform) {
28+
this.mPlatform = platform;
29+
}
30+
31+
@Override
32+
public Class<? extends LibFunction> getMapperClass() {
33+
return VenvyAcrCloudMapper.class;
34+
}
35+
36+
@Override
37+
public LuaValue createCreator(LuaValue env, LuaValue metaTable) {
38+
return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) {
39+
@Override
40+
public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) {
41+
return new VenvyLVAcrClouldCallback(mPlatform,globals, metaTable, varargs);
42+
}
43+
};
44+
}
45+
}

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/binder/VenvyLVLibBinder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import cn.com.venvy.lua.plugin.LVPlayerPlugin;
2424
import cn.com.venvy.lua.plugin.LVPreLoadPlugin;
2525
import cn.com.venvy.lua.plugin.LVRSAPlugin;
26+
import cn.com.venvy.lua.plugin.LVRecordPlugin;
2627
import cn.com.venvy.lua.plugin.LVReportPlugin;
2728
import cn.com.venvy.lua.plugin.LVStatisticsPlugin;
2829
import cn.com.venvy.lua.plugin.LVTableToJsonPlugin;
@@ -59,6 +60,7 @@ void installPlugin(VenvyNativeBinder venvyNativeBinder) {
5960
LVUrlPlugin.install(this);
6061
LVViewManagerPlugin.install(this, venvyNativeBinder.getRootView());
6162
LVLoginPlugin.install(this, venvyNativeBinder.getPlatform());
63+
LVRecordPlugin.install(this, venvyNativeBinder.getPlatform());
6264
LVCachePlugin.install(this);
6365
LVCommonParamPlugin.install(this);
6466
LVTableToJsonPlugin.install(this);
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package cn.com.venvy.lua.maper;
2+
3+
import android.text.TextUtils;
4+
5+
import com.taobao.luaview.fun.mapper.LuaViewLib;
6+
import com.taobao.luaview.fun.mapper.ui.UIViewMethodMapper;
7+
import com.taobao.luaview.util.LuaUtil;
8+
9+
import org.luaj.vm2.LuaFunction;
10+
import org.luaj.vm2.LuaValue;
11+
import org.luaj.vm2.Varargs;
12+
13+
import java.io.File;
14+
import java.util.List;
15+
16+
import cn.com.venvy.common.bean.AcrConfigInfo;
17+
import cn.com.venvy.common.utils.VenvyFileUtil;
18+
import cn.com.venvy.common.utils.VenvyLog;
19+
import cn.com.venvy.lua.binder.VenvyLVLibBinder;
20+
import cn.com.venvy.lua.ud.VenvyUDAcrClouldCallback;
21+
22+
/**
23+
* Created by mac on 18/3/29.
24+
*/
25+
@LuaViewLib(revisions = {"20200226已对标"})
26+
public class VenvyAcrCloudMapper<U extends VenvyUDAcrClouldCallback> extends UIViewMethodMapper<U> {
27+
private static final String TAG = "VenvyAcrCloudMapper";
28+
private static final String[] sMethods = new String[]{
29+
"acrRecognizeCallback",
30+
"startAcrRecognize",
31+
"stopAcrRecognize",
32+
"acrRecordStart",
33+
"acrRecordEnd",
34+
"acrEnable"
35+
};
36+
37+
@Override
38+
public List<String> getAllFunctionNames() {
39+
return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods);
40+
}
41+
42+
@Override
43+
public Varargs invoke(int code, U target, Varargs varargs) {
44+
final int optcode = code - super.getAllFunctionNames().size();
45+
switch (optcode) {
46+
case 0:
47+
return acrRecognizeCallback(target, varargs);
48+
case 1:
49+
return startAcrRecognize(target, varargs);
50+
case 2:
51+
return stopAcrRecognize(target, varargs);
52+
case 3:
53+
return acrRecordStart(target, varargs);
54+
case 4:
55+
return acrRecordEnd(target, varargs);
56+
case 5:
57+
return acrEnable(target, varargs);
58+
}
59+
return super.invoke(code, target, varargs);
60+
}
61+
62+
public LuaValue acrRecognizeCallback(U target, Varargs varargs) {
63+
final LuaFunction callback = varargs.optfunction(2, null);
64+
if (callback != null && callback.isfunction()) {
65+
return target.setAcrCloudCallback(callback);
66+
}
67+
return LuaValue.NIL;
68+
}
69+
70+
public LuaValue startAcrRecognize(U target, Varargs args) {
71+
try {
72+
if (args.narg() > 0) {
73+
String filePath = LuaUtil.getString(args, 2);
74+
if (TextUtils.isEmpty(filePath)) {
75+
VenvyLog.e(VenvyAcrCloudMapper.class.getName(), new NullPointerException("startAcrRecognize is error,because recognize url is null"));
76+
return LuaValue.NIL;
77+
}
78+
String key = LuaUtil.getString(args, 3);
79+
String secret = LuaUtil.getString(args, 4);
80+
if (TextUtils.isEmpty(key) || TextUtils.isEmpty(secret)) {
81+
VenvyLog.e(VenvyAcrCloudMapper.class.getName(), new NullPointerException("startAcrRecognize is error,because key or secret is null"));
82+
return LuaValue.NIL;
83+
}
84+
File file = new File(filePath);
85+
if (!file.exists() || !file.isFile()) {
86+
VenvyLog.e(VenvyAcrCloudMapper.class.getName(), new NullPointerException("startAcrRecognize is error,because recognize url is null"));
87+
return LuaValue.NIL;
88+
}
89+
target.startRecognize(new AcrConfigInfo(key, secret, null), VenvyFileUtil.readBytes(file));
90+
}
91+
} catch (Exception e) {
92+
VenvyLog.e(VenvyAcrCloudMapper.class.getName(), e);
93+
}
94+
return LuaValue.NIL;
95+
}
96+
97+
public LuaValue acrRecordStart(U target, Varargs args) {
98+
try {
99+
target.acrRecordStart();
100+
} catch (Exception e) {
101+
VenvyLog.e(VenvyAcrCloudMapper.class.getName(), e);
102+
}
103+
return LuaValue.NIL;
104+
}
105+
106+
public LuaValue acrRecordEnd(U target, Varargs args) {
107+
final int fixIndex = VenvyLVLibBinder.fixIndex(args);
108+
if (args.narg() > fixIndex) {
109+
final LuaFunction callback = LuaUtil.getFunction(args, fixIndex + 2);
110+
if (callback == null) {
111+
return LuaValue.NIL;
112+
}
113+
target.acrRecordEnd(callback);
114+
}
115+
return LuaValue.NIL;
116+
}
117+
118+
public LuaValue acrEnable(U target, Varargs args) {
119+
return target.acrEnable() ? LuaValue.TRUE : LuaValue.FALSE;
120+
}
121+
122+
public LuaValue stopAcrRecognize(U target, Varargs args) {
123+
try {
124+
target.stopRecognize();
125+
} catch (Exception e) {
126+
VenvyLog.e(VenvyAcrCloudMapper.class.getName(), e);
127+
}
128+
return LuaValue.NIL;
129+
}
130+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package cn.com.venvy.lua.plugin;
2+
3+
import com.taobao.luaview.util.LuaUtil;
4+
5+
import org.luaj.vm2.LuaFunction;
6+
import org.luaj.vm2.LuaValue;
7+
import org.luaj.vm2.Varargs;
8+
import org.luaj.vm2.lib.VarArgFunction;
9+
10+
import cn.com.venvy.Platform;
11+
import cn.com.venvy.common.interf.IPlatformRecordInterface;
12+
import cn.com.venvy.lua.binder.VenvyLVLibBinder;
13+
14+
/**
15+
* Created by lgf on 2020/2/26.
16+
*/
17+
18+
public class LVRecordPlugin {
19+
public static void install(VenvyLVLibBinder venvyLVLibBinder, Platform platform) {
20+
venvyLVLibBinder.set("acrRecordStart", new AcrRecordStart(platform));
21+
venvyLVLibBinder.set("acrRecordEnd", new AcrRecordEnd(platform));
22+
}
23+
24+
/**
25+
* 录制开始事件
26+
*/
27+
private static class AcrRecordStart extends VarArgFunction {
28+
private Platform mPlatform;
29+
30+
AcrRecordStart(Platform platform) {
31+
this.mPlatform = platform;
32+
}
33+
34+
@Override
35+
public Varargs invoke(Varargs args) {
36+
if (mPlatform != null && mPlatform.getPlatformRecordInterface() != null) {
37+
mPlatform.getPlatformRecordInterface().startRecord();
38+
}
39+
return LuaValue.NIL;
40+
}
41+
}
42+
43+
/**
44+
* 录制开始事件
45+
*/
46+
private static class AcrRecordEnd extends VarArgFunction {
47+
private Platform mPlatform;
48+
49+
AcrRecordEnd(Platform platform) {
50+
this.mPlatform = platform;
51+
}
52+
53+
@Override
54+
public Varargs invoke(Varargs args) {
55+
final int fixIndex = VenvyLVLibBinder.fixIndex(args);
56+
if (args.narg() > fixIndex) {
57+
if (mPlatform != null && mPlatform.getPlatformRecordInterface() != null) {
58+
final LuaFunction callback = LuaUtil.getFunction(args, fixIndex + 1);
59+
if (callback == null) {
60+
return LuaValue.NIL;
61+
}
62+
mPlatform.getPlatformRecordInterface().endRecord(new IPlatformRecordInterface.RecordCallback() {
63+
@Override
64+
public void onRecordResult(String filePath) {
65+
LuaUtil.callFunction(callback, LuaValue.valueOf(filePath));
66+
}
67+
});
68+
}
69+
}
70+
return LuaValue.NIL;
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)