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;
});
}
});
编译工程时会发生如下错误:
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)
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)
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)
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)
上述这种应用场景,有没有简便的方法支持多线程共享对象?
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
HarmonyOS ts中继承的类,怎么和C++中的类对象进行绑定
33浏览 • 1回复 待解决
HarmonyOS 如何将C++类作为基类提供给 ArkTS,并在 ArkTS中继承该类
52浏览 • 1回复 待解决
把ts类传到c++层,然后可选择性的运行对应类的方法
852浏览 • 1回复 待解决
ArkTS调用C++类中的成员函数
1342浏览 • 1回复 待解决
如何在不修改类,不继承类的情况下为类添加方法?
338浏览 • 1回复 待解决
HarmonyOS TS类方法重载不能正常使用
12浏览 • 1回复 待解决
如何导出C++自定义类,导出后如何在ArkTS侧进行类方法调用
2243浏览 • 1回复 待解决
HarmonyOS 带泛型的类定义继承之后,子类如何赋值给父类
35浏览 • 0回复 待解决
ts给c++传递数组,c++层如何解析
1934浏览 • 1回复 待解决
HarmonyOS C++的抽象类如何通过NAPI开放给更上层实现
46浏览 • 0回复 待解决
Har如何导出ts类和方法?
429浏览 • 1回复 待解决
HarmonyOS 类可以被继承并重写吗
25浏览 • 1回复 待解决
ArkTS中的类继承机制是怎样的?
174浏览 • 1回复 待解决
HarmonyOS 页面怎么继承基类,有些重复的弹窗想抽到基类中
419浏览 • 1回复 待解决
Uint8Array是@Sendable类吗?
289浏览 • 1回复 待解决
有没有从ts设置回调到c++层,然后c++再回调到ts的示例代码?
1056浏览 • 1回复 待解决
HarmonyOS C/C++库开发 C侧和TS之间的数据交互
654浏览 • 1回复 待解决
HarmonyOS ArkTS支持TS的抽象类吗?
292浏览 • 1回复 待解决
在c++中实例化自定义类并调用方法
346浏览 • 1回复 待解决
HarmonyOS 多个自定义UI组件如何继成自公共的基类
44浏览 • 1回复 待解决
定义一个继承已有类的类,导致进入app首页出现白屏,怎么解决?
429浏览 • 1回复 待解决
HarmonyOS 在RN的TurboModule继承类中不能获取到UIContext
361浏览 • 1回复 待解决
Hierarchy视图里为啥不显示类之间的继承关系
626浏览 • 1回复 待解决
#鸿蒙通关秘籍#如何创建一个继承AttributeModifier的ImageModifier类?
119浏览 • 1回复 待解决
可通过使用Native对象的this指针实现了JS多线程共享Native对象。