Open r2d2Proton opened 4 months ago
I have yet to see Lottie's fail on Windows with the above code.
When I try with SKLottieView some lotties do not render correctly or not at all. . . but that may be due to intermingled calls such as:
private void UpdateProgress(TimeSpan progress)
{
:
lottieData.Animation.SeekFrameTime(progress.TotalSeconds);
}
And would expect a pixel perfect overdraw of the entire animation wtih:
public override void Draw(SKCanvas canvas, RectF dirtyRect)
{
:
lottieData.Animation.Render(canvas, rect);
:
}
In an effort to test with SKLottieView, it was added to my LottieData class and created instead of the version above:
public class LottieData : MyData
{
:
public SKLottieView skLottieView = null;
:
}
public class LottiePlayer
{
:
protected void InitWidget()
{
//CreateLottie();
CreateLottieView();
}
public async Task CreateLottieView()
{
LottieData lottieData = MyData;
if (lottieData != null)
{
if (!string.IsNullOrEmpty(lottieData.Filename))
{
//SKLottieImageSource skLottieImageSource = (SKLottieImageSource)SKLottieImageSource.FromFile(lottieData.Filename);
string lottieStr = Utils.LoadStringResource(lottieData.Filename);
if (!string.IsNullOrEmpty(lottieStr))
{
//Stream stream = new MemoryStream(bytes);
var bytes = System.Text.Encoding.UTF8.GetBytes(lottieStr);
var data = SKData.CreateCopy(bytes);
SKLottieImageSource skLottieImageSource = (SKLottieImageSource)SKLottieImageSource.FromStream(data.AsStream());
await TaskDelay(100);
lottieData.skLottieView = new SKLottieView
{
Source = skLottieImageSource,
IsAnimationEnabled = true,
RepeatCount = -1,
RepeatMode = SKLottieRepeatMode.Reverse,
HeightRequest = lottieData.Height,
WidthRequest = lottieData.Width
};
lottieData.Animation = await lottieData.skLottieView.Source.LoadAnimationAsync();
await TaskDelay(100);
}
}
ResetAnimation();
}
}
protected async Task TaskDelay(int delay)
{
await Task.Delay(delay);
}
Would like to share a fast and (appears) reliable Lottie file loader and player. One that uses SkiaSharp.Skottie.Animation: