English 中文(简体)
What is the preferred way of loading Lottie files from internal folder in a .NET MAUI app?
原标题:

I am in process to migrate Xamarin Forms project to MAUI. I am stuck with SkiaSharp lottieFiles json load issue.

In my app, i download json lottiefile at runtime and save in a app s internal folder. in xamarin, CODE side app can load downloaded file from given path. but in MAUI it is not working from CODE side folder given path.

From last 3 days i tried all kind of path combintation and also tried to search online solutions, but ended up with no luck.

At this point i am testing app with Android API 33. once this start working then i need to do same testing with iphone device.

In Xamarin i was using nuget package - Com.Airbnb.Xamarin.Forms.Lottie.

now in MAUI converted project, i installed nuget package - SkiaSharp.Extended.UI.Maui

This is a part of my code:

Step 1

In my code i am download and saving file to a custom folder.

Download and save process working fine.

readonly string local_lottieJSON_folderName = "lottieJSON";

string ifolderPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), local_lottieJSON_folderName));

XAML code: defaultAnim.json is located at RAWjsondefaultAnim.json.

This part is working fine.

  <skia:SKLottieView
      x:Name="animation_view"
      Source="defaultAnim.json"
    RepeatCount="-1"
    HeightRequest="300"
    HorizontalOptions="Center" />

Step 2: C# Code side load file

SKIA part has the issue

  //This is the path of Downloaded JSON file in varable "imagePath" "/data/user/0/com.companyname.xxxxxxxxxxxmaui/files/lottieJSON/animation_llhn6hu4.json"

 if (File.Exists(imagePath))
  {

      //OLD Airbnb.Xamari working code
      // get file full path and file name
      //string fileName = Path.Combine(imagePath);
      // read file
      //string json = File.ReadAllText(fileName);
      //load the json animation
      //animation_view.SetAnimationFromJson(json);

      //NEW SKIA code for MAUI
      var a = new SKFileLottieImageSource();
      a.File = imagePath;   //// RAW folder working path "json\iamhappy.json";
      animation_view.Source = a;

  }

Extra info: i also tried these paths:

"datausercom.companyname.xxxxxxxxxxxmauifileslottieJSONanimation_llhn6hu4.json"

"/files/lottieJSON/animation_llhn6hu4.json"

"files/lottieJSON/animation_llhn6hu4.json"

"fileslottieJSONanimation_llhn6hu4.json"

"lottieJSONanimation_llhn6hu4.json"

"/lottieJSON/animation_llhn6hu4.json"

I tested with Android emulator and a physical Samsung Android 13 device.

I also tagged Xamarin community, because might someone from xamarin community made this work.

Any advice or direction will be highly appreciable !!!

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签