HarmonyOS 继承自C++类的TS类如何使用Sendable协议
由于SDK核心代码是C++实现,用TS封装了API。
// TS 声明的C++类
import image from '@ohos.multimedia.image';
import { XavThumbnailInfo } from '../../../../ets/videoedit/define/XavThumbnailInfo';
import { XavEditTimeline } from '../../../../ets/videoedit/project/XavEditTimeline';
import { lang, collections } from '@kit.ArkTS'
@Sendable
export declare class NapiThumbnailGetter {
constructor();
destroy: () => void;
getThumbnailFromFilePath: (filePath: string, timestamp: number, timeStep: number, expectWidth: number,
expectHeight: number) => image.PixelMap;
getThumbnailFromTimeline: (timeline: XavEditTimeline, timestamp: number, timeStep: number, expectWidth: number,
expectHeight: number) => image.PixelMap;
getThumbnailInfoFromTimeline: (timeline: XavEditTimeline, trackIndex: number, timestamp: number, timeStep: number,
expectWidth: number, expectHeight: number, thumbnailInfo: XavThumbnailInfo) => boolean;
}
// 继承自C++类的TS API
import NativeSdk from 'libares.so';
@Sendable
export class XavThumbnailGetter extends NativeSdk.NapiThumbnailGetter {
}
// 由于ThumbnailGetter这个类的几个方法耗时高,因此业务层需要另起一个worker或者taskPool执行ThumbnailGetter的方法。类似下面的代码
@Concurrent
function grabberThumbnailFromTimeline(timeline: XavEditTimeline, thumbnailGetter: XavThumbnailGetter,
timeStamp: number): image.PixelMap {
console.info("printArgs: " + timeStamp);
return thumbnailGetter.getThumbnailFromTimeline(timeline, timeStamp, 1000, 100, 100);
}
this.addButton('Timeline抽缩略图异步', () => {
for (let i = 0; i < 100; i++) {
taskpool.execute(grabberThumbnailFromTimeline, this.timeline, this.thumbnailGetter, i * 1000)
.then((image: Object) => {
this.image = this.image;
});
}
});
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
编译工程时会发生如下错误:
ERROR: ArkTS:ERROR File: /Users/user/Development/red/videoeditlib-xhs/harmony/ReDemo/videoedit/src/main/cpp/types/libvideoedit/utils/NapiThumbnailGetter.ets:11:5
Properties in "Sendable" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)
- 1.
- 2.
ERROR: ArkTS:ERROR File: /Users/user/Development/red/videoeditlib-xhs/harmony/ReDemo/videoedit/src/main/cpp/types/libvideoedit/utils/NapiThumbnailGetter.ets:12:5
Properties in "Sendable" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)
- 1.
- 2.
ERROR: ArkTS:ERROR File: /Users/user/Development/red/videoeditlib-xhs/harmony/ReDemo/videoedit/src/main/cpp/types/libvideoedit/utils/NapiThumbnailGetter.ets:14:5
Properties in "Sendable" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)
- 1.
- 2.
ERROR: ArkTS:ERROR File: /Users/user/Development/red/videoeditlib-xhs/harmony/ReDemo/videoedit/src/main/cpp/types/libvideoedit/utils/NapiThumbnailGetter.ets:16:5
Properties in "Sendable" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)
- 1.
- 2.
上述这种应用场景,有没有简便的方法支持多线程共享对象?
HarmonyOS
赞
收藏 0
回答 1
相关问题
HarmonyOS ts中继承的类,怎么和C++中的类对象进行绑定
777浏览 • 1回复 待解决
HarmonyOS 如何将C++类作为基类提供给 ArkTS,并在 ArkTS中继承该类
1022浏览 • 1回复 待解决
把ts类传到c++层,然后可选择性的运行对应类的方法
1383浏览 • 1回复 待解决
HarmonyOS 使用了@Sendable注解的类报错
1138浏览 • 1回复 待解决
ArkTS调用C++类中的成员函数
2324浏览 • 1回复 待解决
如何在不修改类,不继承类的情况下为类添加方法?
1151浏览 • 1回复 待解决
如何导出C++自定义类,导出后如何在ArkTS侧进行类方法调用
3149浏览 • 1回复 待解决
HarmonyOS TS类方法重载不能正常使用
1057浏览 • 1回复 待解决
HarmonyOS 带泛型的类定义继承之后,子类如何赋值给父类
862浏览 • 0回复 待解决
HarmonyOS C++的抽象类如何通过NAPI开放给更上层实现
526浏览 • 0回复 待解决
ts给c++传递数组,c++层如何解析
2793浏览 • 1回复 待解决
Har如何导出ts类和方法?
864浏览 • 1回复 待解决
HarmonyOS 类可以被继承并重写吗
877浏览 • 1回复 待解决
ArkTS中的类继承机制是怎样的?
1226浏览 • 1回复 待解决
Uint8Array是@Sendable类吗?
1002浏览 • 1回复 待解决
HarmonyOS 如何将c++的虚基类封装并提供给ArkTS
949浏览 • 1回复 待解决
HarmonyOS 页面怎么继承基类,有些重复的弹窗想抽到基类中
1174浏览 • 1回复 待解决
有没有从ts设置回调到c++层,然后c++再回调到ts的示例代码?
1787浏览 • 1回复 待解决
HarmonyOS sendable的类在运行单元测试时报错
648浏览 • 1回复 待解决
在c++中实例化自定义类并调用方法
1032浏览 • 1回复 待解决
HarmonyOS ArkTS支持TS的抽象类吗?
1114浏览 • 1回复 待解决
定义一个继承已有类的类,导致进入app首页出现白屏,怎么解决?
999浏览 • 1回复 待解决
HarmonyOS 多个自定义UI组件如何继成自公共的基类
817浏览 • 1回复 待解决
HarmonyOS C/C++库开发 C侧和TS之间的数据交互
1786浏览 • 1回复 待解决
可通过使用Native对象的this指针实现了JS多线程共享Native对象。