HarmonyOS 鸿蒙Next @ohos/lottie报错,无法加载官网demo.json

发布于 1周前 作者 nodeper 最后一次编辑是 5天前 来自 鸿蒙OS

HarmonyOS 鸿蒙Next @ohos/lottie报错,无法加载官网demo.json #HarmonyOS最强问答官#

Error message:Receiver is not a JSObject 06-24 18:41:55.554   12947-12947   E     SourceCode: 06-24 18:41:55.554   12947-12947   E                 animationData.__complete = true; 06-24 18:41:55.554   12947-12947   E                 ^ 06-24 18:41:55.554   12947-12947   E     Stacktrace: 06-24 18:41:55.554   12947-12947   E         at completeData (oh_modules/.ohpm/[@ohos](/user/ohos)+lottie@2.0.11-rc.5/oh_modules/[@ohos](/user/ohos)/lottie/src/main/js/utils/DataManager.js:482:1) 06-24 18:41:55.554   12947-12947   E         at workerStart (oh_modules/.ohpm/[@ohos](/user/ohos)+lottie@2.0.11-rc.5/oh_modules/[@ohos](/user/ohos)/lottie/src/main/js/utils/DataManager.js:619:1) 06-24 18:41:55.554   12947-12947   E         at postMessage (oh_modules/.ohpm/[@ohos](/user/ohos)+lottie@2.0.11-rc.5/oh_modules/[@ohos](/user/ohos)/lottie/src/main/js/utils/DataManager.js:15:1) 06-24 18:41:55.554   12947-12947   E         at completeAnimation (oh_modules/.ohpm/[@ohos](/user/ohos)+lottie@2.0.11-rc.5/oh_modules/[@ohos](/user/ohos)/lottie/src/main/js/utils/DataManager.js:697:1) 06-24 18:41:55.554   12947-12947   E         at anonymous (oh_modules/.ohpm/[@ohos](/user/ohos)+lottie@2.0.11-rc.5/oh_modules/[@ohos](/user/ohos)/lottie/src/main/js/animation/AnimationItem.js:297:1) 06-24 18:41:55.554   12947-12947   E         at anonymous (oh_modules/.ohpm/[@ohos](/user/ohos)+lottie@2.0.11-rc.5/oh_modules/[@ohos](/user/ohos)/lottie/src/main/js/animation/AnimationItem.js:198:1) 06-24 18:41:55.554   12947-12947   E         at loadAnimation (oh_modules/.ohpm/[@ohos](/user/ohos)+lottie@2.0.11-rc.5/oh_modules/[@ohos](/user/ohos)/lottie/src/main/js/animation/AnimationManager.js:91:1) 06-24 18:41:55.554   12947-12947   E         at loadAnimation (oh_modules/.ohpm/[@ohos](/user/ohos)+lottie@2.0.11-rc.5/oh_modules/[@ohos](/user/ohos)/lottie/src/main/js/modules/main.js:44:1) 06-24 18:41:55.554   12947-12947   E         at playLottie (entry/src/main/ets/pages/splash/QuestionPage.ets:21:5) 06-24 18:41:55.554   12947-12947   E         at anonymous (entry/src/main/ets/pages/splash/QuestionPage.ets:52:9)   @Entry @Component export struct QuestionPage {  private mainRenderingSettings: RenderingContextSettings = new RenderingContextSettings(true) private mainCanvasRenderingContext: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.mainRenderingSettings)  aboutToAppear(): void { // let contexts = getContext(this).createModuleContext('library') as common.UIAbilityContext; this.playLottie() }  private playLottie() { let contexts = getContext() as CommonUIContext lottie.loadAnimation({ container: this.mainCanvasRenderingContext, renderer: 'canvas', loop: true, autoplay: true, animationData: LottieHelper.path, context: contexts, contentMode: 'Contain', initialSegment: [10, 50] }); lottie.play() }  build() { NavDestination() { Row() { Column() { Canvas(this.mainCanvasRenderingContext) .width('50%') .height(360 + 'px') .backgroundColor(DEBUG_COLOR) .onReady(()=>{ //抗锯齿的设置 this.mainCanvasRenderingContext.imageSmoothingEnabled = true; this.mainCanvasRenderingContext.imageSmoothingQuality = 'medium' }) } .width('100%') } .height('100%') .onClick(() => { this.playLottie() })  } .backgroundColor(DEBUG_COLOR)  }  }  export class LottieHelper {  static smegmaJson = "{ \"v\": \"5.6.9\... static path: string = "/pages/splash/animation-1718360980137.json"

3 回复

目前窗口管理提供的旋转接口以整个窗口为维度,目前没有办法做到单个page的旋转且不相互影响。执行setPreferredOrientation后,会做出一个旋转动画您可以通过添加页面跳转之后的过渡动效来实现看一下是否效果好一点

```

pageTransition() {
    PageTransitionEnter({
        duration: 200,
        delay: 100
    })
    .opacity(0);
PageTransitionExit({
    duration: <span class="hljs-number">200</span>
})
.opacity(<span class="hljs-number">0</span>);

} <button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>

```

animationData本质是传入json数据,你这里只是传入了string路径,修改为path

针对HarmonyOS 鸿蒙Next中@ohos/lottie报错,无法加载官网demo.json的问题,这通常与多个因素有关。首先,请确保lottie库已正确导入并配置在项目中,同时检查demo.json文件是否放置在正确的目录下,并确保路径无误。

其次,检查使用lottie.loadAnimation方法加载动画时,参数设置如容器、渲染器、循环播放等是否符合需求。如果资源文件或路径损坏、错误,也可能导致动画无法加载。

此外,版本问题也可能导致报错。请尝试固定@ohos/lottie的版本号,并清理项目后重新同步。

最后,如果以上步骤均无法解决问题,请检查开发环境和工具的版本是否兼容,以及是否有其他依赖冲突。

如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html

回到顶部