Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core-render-ohos/src/main/ets/adapter/IKRPAGViewAdapter.ets
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface IKRPAGViewController {
play(): void;

stop(): void;

setProgress(value: number): void;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

接口新增方法 建议文档备注 方便业务SDK升级适配

}

export interface IKRPAGViewListener {
Expand Down
41 changes: 37 additions & 4 deletions core-render-ohos/src/main/ets/components/KRPAGView.ets
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export class KRPAGView extends KuiklyRenderBaseView implements IKRPAGViewListene
src: string = '';
autoPlay: boolean = true;
repeatCount = 0;
private hadSrcSet: boolean = false;
private hadStop: boolean = false;
controller: IKRPAGViewController | undefined;
static readonly VIEW_NAME = 'KRPAGView';
private static readonly PROP_SRC = 'src';
Expand All @@ -73,6 +75,7 @@ export class KRPAGView extends KuiklyRenderBaseView implements IKRPAGViewListene
private static readonly EVENT_ANIMATION_REPEAT = 'animationRepeat';
private static readonly PROP_METHOD_PLAY = 'play';
private static readonly PROP_METHOD_STOP = 'stop';
private static readonly PROP_METHOD_SET_PROGRESS = 'setProgress';

private static readonly SCHEME_ASSETS = "assets://";
private static readonly SCHEME_FILE = "files://";
Expand All @@ -89,10 +92,20 @@ export class KRPAGView extends KuiklyRenderBaseView implements IKRPAGViewListene
this.animationCancelEvent = propValue as KuiklyRenderCallback;
} else if (propKey == KRPAGView.EVENT_ANIMATION_REPEAT) {
this.animationRepeatEvent = propValue as KuiklyRenderCallback;
} else {
if (propKey == KRPAGView.PROP_SRC) {
propValue = this.convertAssetsPathIfNeed(propValue as string)
} else if (propKey == KRPAGView.PROP_AUTO_PLAY) {
this.autoPlay = (propValue as number) == 1;
if (this.autoPlay) {
this.tryAutoPlay();
}
} else if (propKey == KRPAGView.PROP_SRC) {
propValue = this.convertAssetsPathIfNeed(propValue as string);
this.src = propValue as string;
this.hadSrcSet = true;
if (this.controller) {
this.controller.setProp(propKey, propValue);
}
setTimeout(() => { this.tryAutoPlay(); });
} else {
if (this.controller) {
return this.controller?.setProp(propKey, propValue);
} else {
Expand All @@ -106,9 +119,29 @@ export class KRPAGView extends KuiklyRenderBaseView implements IKRPAGViewListene
call(method: string, params: KRAny, callback: KuiklyRenderCallback | null): void {
console.log(`KRPAGView call method :${method}`);
if (method == KRPAGView.PROP_METHOD_PLAY) {
this.autoPlay = true;
this.hadStop = false;
this.controller?.play();
} else if (method == KRPAGView.PROP_METHOD_STOP) {
this.controller?.stop();
this.autoPlay = false;
if (!this.hadStop) {
this.hadStop = true;
this.controller?.stop();
}
} else if (method == KRPAGView.PROP_METHOD_SET_PROGRESS) {
if (typeof params === 'string') {
const json: Record<string, Object> = JSON.parse(params as string) as Record<string, Object>;
const value = json['value'] as number;
if (value !== undefined) {
this.controller?.setProgress(value);
}
}
}
}

private tryAutoPlay(): void {
if (this.autoPlay && this.hadSrcSet && !this.hadStop) {
this.controller?.play();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class AppKRPAGViewController implements IKRPAGViewController, PAGViewListener {
this.viewController.pause();
}

setProgress(value: number): void {
this.viewController.setProgress(value);
}

setProp(propKey: string, propValue: KRValue | KuiklyRenderCallback): boolean {
if (propKey == 'src') {
const resdir = getContext().resourceDir;
Expand Down