private void HandleTimerTick() { try { int[] data = new int[3]; byte[] videoFrame = FFmpegGifDecoder.GetVideoFrame(this._handler, data); if (this._pts == 0 && data[2] != 0) { this._pts = data[2]; this._timer.Interval = (TimeSpan.FromMilliseconds((double)this._pts)); } if (!this._isPlaying) { return; } for (int index1 = 0; index1 < this._wb.Pixels.Length; ++index1) { int index2 = index1 << 2; this._wb.Pixels[index1] = -16777216 | (int)videoFrame[index2] << 16 | (int)videoFrame[index2 + 1] << 8 | (int)videoFrame[index2 + 2]; } this._wb.Invalidate(); this.imageGif.Source = ((ImageSource)this._wb); } catch (Exception ex) { Logger.Instance.Error("FFmpegGifPlayerUC.HandleTimerTick failed", ex); } }
private async void UpdateFileName(string newFileName) { this.Stop(); this.Release(); if (string.IsNullOrEmpty(newFileName)) { return; } try { string path = (await CacheManager.GetFileAsync(newFileName)).Path; this._decoderParams = new int[3]; this._handler = FFmpegGifDecoder.CreateDecoder(path, this._decoderParams); if (this._handler <= 0) { return; } this._w = this._decoderParams[0]; this._h = this._decoderParams[1]; if (this._w <= 0 || this._h <= 0) { return; } this._wb = new WriteableBitmap(this._w, this._h); this._isInitialized = true; this.Start(); } catch (Exception ex) { Logger.Instance.Error("FFmpegGifPlayerUC.UpdateFileName failed", ex); } }
private void Release() { if (this._handler != 0) { try { FFmpegGifDecoder.DestroyDecoder(this._handler); } catch (Exception ex) { Logger.Instance.Error("FFmpegGifPlayerUC.Release failed", ex); } this._handler = 0; } this.imageGif.Source = (null); this._isPlaying = false; this._isInitialized = false; this._w = 0; this._h = 0; this._pts = 0; }