1

I am learning xamarin Forms. I would to read my lottie file named "LeafGameAnim.json" in c# but the animation not display

My xaml looks like this :

<forms:AnimationView
AnimationSource="EmbeddedResource"
x:Name="LeafGame_Anim"
 IsVisible="True"     
RepeatMode="Infinite"
AutoPlay="True"  />

My C# looks like this :

var jsonFileName = "Les.MyData.MyAnimation.LeafGameAnim.json";
var assembly = typeof(MainPage).GetTypeInfo().Assembly;
Stream stream = assembly.GetManifestResourceStream(jsonFileName);

using (var reader = new System.IO.StreamReader(stream))
{
    var json = reader.ReadToEnd();
   LeafGame_Anim.SetAnimationFromJson(json);   
}

Thanks for your help

hk77
  • 59
  • 8
  • Look at this example of how to specify the AnimationSource in the XAML: https://github.com/Baseflow/LottieXamarin/blob/develop/Samples/Forms/Example.Forms/Pages/EmbeddedPage.xaml – Jason Oct 08 '22 at 12:24
  • @Jason this work on Xaml I would like to read from .Net code . I have updated my code – hk77 Oct 08 '22 at 12:43
  • The method you had in the original post takes a json string, not a file name. There are many existing posts about how to read the contents of an embedded resource – Jason Oct 08 '22 at 13:19
  • @Jason I am still looking. If any one have a solution I will take it – hk77 Oct 08 '22 at 13:41
  • https://stackoverflow.com/questions/3314140/how-to-read-embedded-resource-text-file – Jason Oct 08 '22 at 13:57
  • it still not working – hk77 Oct 09 '22 at 03:51
  • Please edit your question to show the current state of your code. “Not working” is not a useful description of your problem – Jason Oct 09 '22 at 10:30
  • I have updated: by "not working" I am saying , the animation does not appear – hk77 Oct 09 '22 at 11:46
  • 1
    You do not appear to be following any of my suggestions. You are not using the `SetAnimationFromJson` method you had in your original post, and you are not loading the json file from Resources as shown in the linked post – Jason Oct 09 '22 at 11:48
  • @Jason I have update the code. The animation still not appear – hk77 Oct 09 '22 at 13:30
  • 1
    Your resourceName is not correct. If you debug the code it should be obvious that it is not reading the file – Jason Oct 09 '22 at 13:47
  • @Jason I have update the post with the structure of my code – hk77 Oct 09 '22 at 14:01
  • Is that files build action set to EmbeddedResource? – Jason Oct 09 '22 at 14:10
  • @Jason Yes you were right it is working now – hk77 Oct 09 '22 at 14:19

0 Answers0