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:
"datauser com.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 !!!