private async void Button_Click(object sender, RoutedEventArgs e) { try { var file = await Package.Current.InstalledLocation.GetFileAsync($"{_stickers[index]}.tgs"); var result = await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.ReplaceExisting); } catch { } using (var lottie = CachedAnimation.LoadFromFile(ApplicationData.Current.LocalFolder.Path + $"\\{_stickers[index]}.tgs", false, true, null)) { Pic.Source = lottie.RenderSync(0, 256, 256); } //var player = new LottieView //{ // Width = 200, // Height = 200, // Source = new Uri($"ms-appdata://local/{_stickers[index]}.tgs") //}; //Panel.Children.Add(player); //index = (index + 1) % _stickers.Length; }
private IAnimation LoadFromFile(string path, bool cache) { if (cache) { return(CachedAnimation.LoadFromFile(path, true, _limitFps)); } return(Animation.LoadFromFile(path)); }
private void OnSourceChanged(string newValue, string oldValue) { var canvas = _canvas; if (canvas == null) { return; } if (newValue == null) { //canvas.Paused = true; //canvas.ResetElapsedTime(); Subscribe(false); Dispose(); return; } if (string.Equals(newValue, oldValue, StringComparison.OrdinalIgnoreCase) || string.Equals(newValue, _source, StringComparison.OrdinalIgnoreCase)) { return; } var animation = CachedAnimation.LoadFromFile(newValue, _isCachingEnabled, _limitFps, ColorReplacements); if (animation == null) { // The app can't access the file specified return; } _source = newValue; _animation = animation; _animationIsCached = !animation.ShouldCache; _animationFrameRate = animation.FrameRate; _animationTotalFrame = animation.TotalFrame; _index = _isCachingEnabled ? 0 : _animationTotalFrame - 1; var update = TimeSpan.FromSeconds(_animation.Duration / _animation.TotalFrame); if (_limitFps && _animation.FrameRate >= 60) { update = TimeSpan.FromSeconds(update.TotalSeconds * 2); } //canvas.Paused = true; //canvas.ResetElapsedTime(); //canvas.TargetElapsedTime = update > TimeSpan.Zero ? update : TimeSpan.MaxValue; if (AutoPlay || _shouldPlay) { _shouldPlay = false; Subscribe(true); //canvas.Paused = false; } else { Subscribe(false); // Invalidate to render the first frame Invalidate(); _canvas.Invalidate(); } }