private void Play(GifPlayStartType startType, bool suppressStats)
 {
     if (this._state == InplaceGifViewerViewModel.State.NotStarted || this._state == InplaceGifViewerViewModel.State.Failed)
     {
         this.CurrentState = InplaceGifViewerViewModel.State.Downloading;
         Stream stream = CacheManager.GetStreamForWrite(this._localFile);
         this._currentCancellationToken = new Cancellation();
         JsonWebRequest.Download(this.VideoUri, stream, (Action <bool>)(res => Execute.ExecuteOnUIThread((Action)(() =>
         {
             try
             {
                 if (this._currentCancellationToken.IsSet)
                 {
                     this.CurrentState = InplaceGifViewerViewModel.State.Failed;
                     stream.Close();
                     CacheManager.TryDelete(this._localFile, CacheManager.DataType.CachedData);
                 }
                 else
                 {
                     int fileSize = (int)stream.Length;
                     stream.Close();
                     if (res)
                     {
                         MediaLRUCache.Instance.AddLocalFile(this.VideoUri, this._localFile, fileSize);
                         this.CurrentState = InplaceGifViewerViewModel.State.Downloaded;
                         this.CurrentState = InplaceGifViewerViewModel.State.Playing;
                         this.SendGifPlayStats(startType, suppressStats);
                     }
                     else
                     {
                         this.CurrentState = InplaceGifViewerViewModel.State.Failed;
                         CacheManager.TryDelete(this._localFile, CacheManager.DataType.CachedData);
                     }
                 }
             }
             catch
             {
                 try
                 {
                     stream.Close();
                 }
                 catch
                 {
                 }
                 this.CurrentState = InplaceGifViewerViewModel.State.Failed;
                 CacheManager.TryDelete(this._localFile, CacheManager.DataType.CachedData);
             }
         }))), (Action <double>)(progress => this.DownloadProgress = progress), this._currentCancellationToken);
     }
     else
     {
         if (this._state != InplaceGifViewerViewModel.State.Downloaded)
         {
             return;
         }
         this.CurrentState = InplaceGifViewerViewModel.State.Playing;
         this.SendGifPlayStats(startType, suppressStats);
     }
 }
 private void SendGifPlayStats(GifPlayStartType startType, bool suppressStats)
 {
     if (this._doc == null | suppressStats)
     {
         return;
     }
     if (startType == GifPlayStartType.autoplay)
     {
         if (this._autoplayStatsSent)
         {
             return;
         }
         this._autoplayStatsSent = true;
     }
     EventAggregator.Current.Publish(new GifPlayEvent(string.Format("{0}_{1}", this._doc.owner_id, this._doc.id), startType, CurrentMediaSource.GifPlaySource));
 }
 public void Play(GifPlayStartType startType = GifPlayStartType.manual)
 {
     this.Play(startType, false);
 }
Ejemplo n.º 4
0
 public GifPlayEvent(string gifId, GifPlayStartType startType, StatisticsActionSource source)
 {
     this.GifId     = gifId;
     this.StartType = startType;
     this.Source    = source;
 }