HarmonyOS 鸿蒙Next中lottie可以加载json文件,但是只有一帧,无法播放
HarmonyOS 鸿蒙Next中lottie可以加载json文件,但是只有一帧,无法播放 使用lottie可以正确加载json文件,但是只有一帧,无法完整播放。 按照官方教程做的,这怎么解决啊? 求帮助。
import lottie, { AnimationItem } from '@ohos/lottie'
@Entry
@Component
struct LottiePage {
private renderingContext: CanvasRenderingContext2D = new CanvasRenderingContext2D()
private animateName: string = 'chicky'
private animatePath: string = 'common/lottie/chicky.json'
private animateItem: AnimationItem = null
onPageHide() {
console.log('onPageHide')
lottie.destroy()
}
loadAnimation(){
console.log('canvas onAppear');
if (this.animateItem != null) {
this.animateItem.destroy()
this.animateItem = null
}
this.animateItem = lottie.loadAnimation({
container: this.renderingContext,
renderer: 'canvas',
loop: true,
autoplay: true,
name: this.animateName,
path: this.animatePath,
initialSegment: [60, 120],
})
}
build() {
Column({space:20}){
Canvas(this.renderingContext)
.width('50%')
.height('50%')
.backgroundColor('#0D9FFB')
.onReady(() => {
this.loadAnimation()
})
Button('Load Animation')
.onClick(() => {
this.loadAnimation()
})
Button('destroy animation')
.onClick(() => {
lottie.destroy(this.animateName)
this.animateItem = null
})
Button('pause')
.onClick(()=>{
lottie.pause(this.animateName)
})
Button('play')
.onClick(()=>{
lottie.play(this.animateName)
})
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
}
更多关于HarmonyOS 鸿蒙Next中lottie可以加载json文件,但是只有一帧,无法播放的实战教程也可以访问 https://www.itying.com/category-93-b0.html
7 回复
我也出现过,升级到2.0.11-rc.1解决。
更多关于HarmonyOS 鸿蒙Next中lottie可以加载json文件,但是只有一帧,无法播放的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
换行符换成官方的data.json,还是不行,只有一帧
换了,不行,还是只有一帧,
那就是代码问题,
在HarmonyOS鸿蒙Next中,Lottie加载JSON文件后只有一帧且无法播放,可能是以下原因导致:
- JSON文件损坏或不完整:确保JSON文件是从Lottie官方工具导出且未损坏。
- 版本兼容性问题:检查Lottie库版本是否与HarmonyOS版本兼容,建议使用最新版本。
- 动画帧率设置问题:确认动画帧率设置正确,避免帧率过低导致动画无法播放。
- 代码调用错误:确保正确调用Lottie的播放方法,如
start()
或playAnimation()
。
建议先检查JSON文件完整性,并更新Lottie库,确保代码正确调用播放方法。