frankvHoof93 / TikTokLiveSharp

Port of TikTok live library for C#
https://vanhoof.dev
Other
139 stars 27 forks source link

[QUESTION] Getting User Image #51

Closed Zaisu closed 7 months ago

Zaisu commented 7 months ago

Hi,

I'm kinda fresh in Unity - it's all chaos for me. Question may be really stupid but how can I get user profile picture? I would like to show it on screen, but everything i can find is something in "Picture" format while I need Image or at least Sprite.

Thanks for ur time!

Zaisu commented 7 months ago

Ok, I kinda solved my problem - now I have different one. I discovered RequestImage() function, but I'm not sure how im supposed to use it. Avatars have latency while I try to put them on objects, it is me or maybe it works like this? Second thing - I'm trying to get Sprite from this Images and put it into player prefabs then join them into game - everytime i try those use those they are saved as null value so i end up with invisible objects. How can i solve this? :P

frankvHoof93 commented 7 months ago
  1. Avatars have latency while I try to put them on objects, it is me or maybe it works like this?

This 'latency' is the time between when you call RequestImage, and when the download of that image finishes. The 'Picture'-object is what the TikTok-server provides. This contains a (list of) Url(s) to the image on TikTok's CDN-server. The RequestImage()-method is a wrapper around Unity's normal UnityWebRequest-functionality to download this image (it also caches images, so subsequent requests don't need to do another download). Once the download finishes, the RequestImage's callback function returns the downloaded image (Texture/Sprite).

  1. I'm trying to get Sprite from this Images and put it into player prefabs then join them into game - everytime i try those use those they are saved as null value so i end up with invisible objects.

Downloaded Images exist only in RAM. If you want to save them to a prefab, you'll need to write the image to disk first. An example of how to do this is discussed here: https://forum.unity.com/threads/save-rendertexture-or-texture2d-as-image-file-utility.1325130/#post-8387577