LottieFiles / lottie-player

Lottie viewer/player as an easy to use web component! https://lottiefiles.com/web-player
MIT License
1.55k stars 174 forks source link

JSON string is interpreted as URL #200

Open iwo-strzebonski opened 1 year ago

iwo-strzebonski commented 1 year ago

Hello, I'm currently working with Frontify Brand SDK and Typescript React and I wanted to use the LottiePlayer with a JSON string loaded from the file input, however I receive an error suggesting that the player tries to use that string as URL instead of a JSON.

I tried passing a parsed JSON, without success.

samuelOsborne commented 1 year ago

hi @iwo-strzebonski Could you share how you tried passing a parsed json?

Also, are you aware of https://github.com/LottieFiles/lottie-react ? This could be helpful, cheers!

iwo-strzebonski commented 1 year ago

@samuelOsborne the JSON is shown correctly in the console Also I see now that I receive an error "lottiePlayer.load() is not a function", though the element itself exists

const lottiePlayer = document.querySelector('lottie-player') as any

if (!lottiePlayer) {
   return
}

console.debug(JSON.parse(src))
lottiePlayer.load(JSON.parse(src))
samuelOsborne commented 1 year ago

Hi @iwo-strzebonski What framework are you using? I've tried to reproduce here but seems to be working as intended, let me know if theres a difference with your code

https://codepen.io/Osbro/pen/ExeEeav