Skip to content

Commit 1d98bd1

Browse files
committed
add acrRecordStart acrRecordEnd api
1 parent f757f5a commit 1d98bd1

File tree

7 files changed

+83
-18
lines changed

7 files changed

+83
-18
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private static void registerNativeLibs(@NonNull LuaView luaView, Platform platfo
7878
luaView.registerLibs(getUiGradientViewBinder(),
7979
getMediaLifeCycleBinder(platform),
8080
getMqttBinder(),
81-
getAcrCloudBinder(),
81+
getAcrCloudBinder(platform),
8282
getAppletBinder(platform),
8383
getSvgaBinder(),
8484
getWebViewBinder(platform),
@@ -126,8 +126,10 @@ private static VenvyMqttBinder getMqttBinder() {
126126
return venvyMqttBinder == null ? venvyMqttBinder = new VenvyMqttBinder() : venvyMqttBinder;
127127
}
128128

129-
private static VenvyAcrCloudBinder getAcrCloudBinder() {
130-
return acrCloudBinder == null ? acrCloudBinder = new VenvyAcrCloudBinder() : acrCloudBinder;
129+
private static VenvyAcrCloudBinder getAcrCloudBinder(Platform platform) {
130+
VenvyAcrCloudBinder venvyAcrCloudBinder = acrCloudBinder == null ? acrCloudBinder = new VenvyAcrCloudBinder() : acrCloudBinder;
131+
venvyAcrCloudBinder.setPlatform(platform);
132+
return venvyAcrCloudBinder;
131133
}
132134

133135
private static VenvyAppletBinder getAppletBinder(Platform platform) {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.luaj.vm2.Varargs;
1010
import org.luaj.vm2.lib.LibFunction;
1111

12+
import cn.com.venvy.Platform;
1213
import cn.com.venvy.lua.maper.VenvyAcrCloudMapper;
1314
import cn.com.venvy.lua.view.VenvyLVAcrClouldCallback;
1415

@@ -17,11 +18,16 @@
1718
*/
1819

1920
public class VenvyAcrCloudBinder extends BaseFunctionBinder {
21+
private Platform mPlatform;
2022

2123
public VenvyAcrCloudBinder() {
2224
super("AcrCloud");
2325
}
2426

27+
public void setPlatform(Platform platform) {
28+
this.mPlatform = platform;
29+
}
30+
2531
@Override
2632
public Class<? extends LibFunction> getMapperClass() {
2733
return VenvyAcrCloudMapper.class;
@@ -32,7 +38,7 @@ public LuaValue createCreator(LuaValue env, LuaValue metaTable) {
3238
return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) {
3339
@Override
3440
public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) {
35-
return new VenvyLVAcrClouldCallback(globals, metaTable, varargs);
41+
return new VenvyLVAcrClouldCallback(mPlatform,globals, metaTable, varargs);
3642
}
3743
};
3844
}

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/maper/VenvyAcrCloudMapper.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import cn.com.venvy.common.bean.AcrConfigInfo;
1717
import cn.com.venvy.common.utils.VenvyFileUtil;
1818
import cn.com.venvy.common.utils.VenvyLog;
19+
import cn.com.venvy.lua.binder.VenvyLVLibBinder;
1920
import cn.com.venvy.lua.ud.VenvyUDAcrClouldCallback;
2021

2122
/**
@@ -28,6 +29,8 @@ public class VenvyAcrCloudMapper<U extends VenvyUDAcrClouldCallback> extends UIV
2829
"acrRecognizeCallback",
2930
"startAcrRecognize",
3031
"stopAcrRecognize",
32+
"acrRecordStart",
33+
"acrRecordEnd"
3134
};
3235

3336
@Override
@@ -45,6 +48,10 @@ public Varargs invoke(int code, U target, Varargs varargs) {
4548
return startAcrRecognize(target, varargs);
4649
case 2:
4750
return stopAcrRecognize(target, varargs);
51+
case 3:
52+
return acrRecordStart(target, varargs);
53+
case 4:
54+
return acrRecordEnd(target, varargs);
4855
}
4956
return super.invoke(code, target, varargs);
5057
}
@@ -84,6 +91,27 @@ public LuaValue startAcrRecognize(U target, Varargs args) {
8491
return LuaValue.NIL;
8592
}
8693

94+
public LuaValue acrRecordStart(U target, Varargs args) {
95+
try {
96+
target.acrRecordStart();
97+
} catch (Exception e) {
98+
VenvyLog.e(VenvyAcrCloudMapper.class.getName(), e);
99+
}
100+
return LuaValue.NIL;
101+
}
102+
103+
public LuaValue acrRecordEnd(U target, Varargs args) {
104+
final int fixIndex = VenvyLVLibBinder.fixIndex(args);
105+
if (args.narg() > fixIndex) {
106+
final LuaFunction callback = LuaUtil.getFunction(args, fixIndex + 1);
107+
if (callback == null) {
108+
return LuaValue.NIL;
109+
}
110+
target.acrRecordEnd(callback);
111+
}
112+
return LuaValue.NIL;
113+
}
114+
87115
public LuaValue stopAcrRecognize(U target, Varargs args) {
88116
try {
89117
target.stopRecognize();

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/plugin/LVRecordPlugin.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import cn.com.venvy.common.interf.IPlatformRecordInterface;
1212
import cn.com.venvy.lua.binder.VenvyLVLibBinder;
1313

14-
import static android.R.attr.data;
15-
1614
/**
1715
* Created by lgf on 2020/2/26.
1816
*/
@@ -62,11 +60,6 @@ public Varargs invoke(Varargs args) {
6260
return LuaValue.NIL;
6361
}
6462
mPlatform.getPlatformRecordInterface().endRecord(new IPlatformRecordInterface.RecordCallback() {
65-
@Override
66-
public void onRecordResult(byte[] data) {
67-
LuaUtil.callFunction(callback, LuaValue.valueOf(data));
68-
}
69-
7063
@Override
7164
public void onRecordResult(String filePath) {
7265
LuaUtil.callFunction(callback, LuaValue.valueOf(filePath));

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/ud/VenvyUDAcrClouldCallback.java

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,32 @@
88
import com.taobao.luaview.util.LuaUtil;
99

1010
import org.luaj.vm2.Globals;
11+
import org.luaj.vm2.LuaFunction;
1112
import org.luaj.vm2.LuaValue;
1213
import org.luaj.vm2.Varargs;
1314

15+
import cn.com.venvy.Platform;
1416
import cn.com.venvy.common.acr.VenvyACRCloudFactory;
1517
import cn.com.venvy.common.bean.AcrConfigInfo;
1618
import cn.com.venvy.common.interf.IACRCloud;
19+
import cn.com.venvy.common.interf.IPlatformRecordInterface;
20+
import cn.com.venvy.common.utils.VenvyLog;
1721
import cn.com.venvy.lua.view.VenvyLVAcrClouldCallback;
1822

1923
/**
2024
* Created by lgf on 2020/2/26.
2125
*/
2226

2327
public class VenvyUDAcrClouldCallback extends UDView<VenvyLVAcrClouldCallback> {
28+
private static final String TAG = VenvyUDAcrClouldCallback.class.getName();
2429
private IACRCloud mAcrCloud;
2530
LuaValue mAcrCloudCallback;
31+
private Platform mPlatform;
2632

27-
public VenvyUDAcrClouldCallback(VenvyLVAcrClouldCallback view, Globals globals, LuaValue metatable, Varargs initParams) {
33+
public VenvyUDAcrClouldCallback(Platform platform, VenvyLVAcrClouldCallback view, Globals globals, LuaValue metatable, Varargs initParams) {
2834
super(view, globals, metatable, initParams);
2935
mAcrCloud = VenvyACRCloudFactory.getACRCloud();
36+
this.mPlatform = platform;
3037
}
3138

3239
public VenvyUDAcrClouldCallback setAcrCloudCallback(LuaValue callbacks) {
@@ -47,9 +54,9 @@ public void handleAcrMessageBundle(Bundle bundle) {
4754
LuaUtil.callFunction(mMqttCallback, JsonUtil.toLuaTable(message));
4855
}
4956

50-
public void startRecognize(AcrConfigInfo info,byte[] buffer) {
57+
public void startRecognize(AcrConfigInfo info, byte[] buffer) {
5158
if (mAcrCloud != null) {
52-
mAcrCloud.startRecognize(info,buffer);
59+
mAcrCloud.startRecognize(info, buffer);
5360
}
5461
}
5562

@@ -59,6 +66,35 @@ public void stopRecognize() {
5966
}
6067
}
6168

69+
public void acrRecordStart() {
70+
if (mPlatform == null) {
71+
return;
72+
}
73+
IPlatformRecordInterface platformRecord = mPlatform.getPlatformRecordInterface();
74+
if (platformRecord == null) {
75+
VenvyLog.i(TAG, "start acrRecordStart error,because VideoPlusAdapter no interface buildRecordInterface");
76+
return;
77+
}
78+
platformRecord.startRecord();
79+
}
80+
81+
public void acrRecordEnd(final LuaFunction callback) {
82+
if (mPlatform == null || callback == null) {
83+
return;
84+
}
85+
IPlatformRecordInterface platformRecord = mPlatform.getPlatformRecordInterface();
86+
if (platformRecord == null) {
87+
VenvyLog.i(TAG, "start acrRecordStart error,because VideoPlusAdapter no interface buildRecordInterface");
88+
return;
89+
}
90+
platformRecord.endRecord(new IPlatformRecordInterface.RecordCallback() {
91+
@Override
92+
public void onRecordResult(String filePath) {
93+
LuaUtil.callFunction(callback, LuaValue.valueOf(filePath));
94+
}
95+
});
96+
}
97+
6298
public void destroyRecognize() {
6399
if (mAcrCloud != null) {
64100
mAcrCloud.destroyRecognize();

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/view/VenvyLVAcrClouldCallback.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.luaj.vm2.LuaValue;
1111
import org.luaj.vm2.Varargs;
1212

13+
import cn.com.venvy.Platform;
1314
import cn.com.venvy.common.observer.ObservableManager;
1415
import cn.com.venvy.common.observer.VenvyObservable;
1516
import cn.com.venvy.common.observer.VenvyObserver;
@@ -24,9 +25,9 @@
2425
public class VenvyLVAcrClouldCallback extends View implements ILVView, VenvyObserver {
2526
private VenvyUDAcrClouldCallback mLuaUserdata;
2627

27-
public VenvyLVAcrClouldCallback(Globals globals, LuaValue metaTable, Varargs varargs) {
28+
public VenvyLVAcrClouldCallback(Platform platform, Globals globals, LuaValue metaTable, Varargs varargs) {
2829
super(globals.getContext());
29-
this.mLuaUserdata = new VenvyUDAcrClouldCallback(this, globals, metaTable, varargs);
30+
this.mLuaUserdata = new VenvyUDAcrClouldCallback(platform, this, globals, metaTable, varargs);
3031
}
3132

3233
@Override
@@ -51,7 +52,7 @@ protected void onDetachedFromWindow() {
5152

5253
@Override
5354
public void notifyChanged(VenvyObservable observable, String tag, Bundle bundle) {
54-
if(mLuaUserdata!=null){
55+
if (mLuaUserdata != null) {
5556
mLuaUserdata.handleAcrMessageBundle(bundle);
5657
}
5758
}

VideoOS/VenvyLibrary/src/main/java/cn/com/venvy/common/interf/IPlatformRecordInterface.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public interface IPlatformRecordInterface {
88
void startRecord();
99
void endRecord(RecordCallback loginCallback);
1010
interface RecordCallback {
11-
void onRecordResult(byte[] data);
1211
void onRecordResult(String filePath);
1312
}
1413
}

0 commit comments

Comments
 (0)