public void Play() { if (this._currentState == VoiceMessageAttachmentViewModel.State.NotStarted || this._currentState == VoiceMessageAttachmentViewModel.State.Failed) { this.CurrentState = VoiceMessageAttachmentViewModel.State.Downloading; Stream stream = CacheManager.GetStreamForWrite(this._localFile); this._currentCancellationToken = new Cancellation(); JsonWebRequest.Download(this.VideoUri, stream, delegate(bool res) { Execute.ExecuteOnUIThread(delegate { try { if (this._currentCancellationToken.IsSet) { this.CurrentState = VoiceMessageAttachmentViewModel.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 = VoiceMessageAttachmentViewModel.State.Downloaded; this.CurrentState = VoiceMessageAttachmentViewModel.State.Playing; } else { this.CurrentState = VoiceMessageAttachmentViewModel.State.Failed; CacheManager.TryDelete(this._localFile, CacheManager.DataType.CachedData); } } } catch { try { stream.Close(); } catch { } this.CurrentState = VoiceMessageAttachmentViewModel.State.Failed; CacheManager.TryDelete(this._localFile, CacheManager.DataType.CachedData); } }); }, delegate(double progress) { this.DownloadProgress = progress; }, this._currentCancellationToken); return; } if (this._currentState == VoiceMessageAttachmentViewModel.State.Downloaded) { this.CurrentState = VoiceMessageAttachmentViewModel.State.Playing; } }
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); } }
public void PlayPause() { this._isDownloaded = MediaLRUCache.Instance.HasLocalFile(this._sourceUriStr); if (this._isDownloaded) { this.DoPlayPause(); } else if (this._isDownloading) { this._downloadCancellation.Set(); } else { string str = Guid.NewGuid().ToString(); this._wavFileName = string.Format("{0}.wav", str); if (this._sourceUriStr.IsExternal()) { this._isDownloading = true; string fileId = string.Format("{0}.ogg", str); this._opusFilePath = CacheManager.GetFullFilePath(fileId, CacheManager.DataType.CachedData); this._downloadCancellation = new Cancellation(); Stream opusStream = CacheManager.GetStreamForWrite(fileId); JsonWebRequest.Download(this._sourceUriStr, opusStream, (Action <bool>)(isDownloaded => { opusStream.Close(); Execute.ExecuteOnUIThread((Action)(() => { try { if (!isDownloaded) { return; } this.ConvertOpusToWavAndPlay(); } finally { this._isDownloading = false; } })); }), (Action <double>)(progress => {}), this._downloadCancellation); } else { this._opusFilePath = this._sourceUriStr; this.ConvertOpusToWavAndPlay(); } } }
private void LoadUris(List <string> list) { foreach (string str in list) { string uri = str; if (!this._loadedUris.ContainsKey(uri)) { JsonWebRequest.Download(uri, 0, 0, (Action <HttpStatusCode, long, byte[]>)((statusCode, b, c) => { if (statusCode != HttpStatusCode.OK) { return; } Execute.ExecuteOnUIThread((Action)(() => this._loadedUris[uri] = "true")); })); } } }
private void PerformChunkDownload(InProgressDownloadInfo di, Action resultCallback) { JsonWebRequest.Download(di.RemoteFile.UriStr, di.DownloadedToByte + 1L, di.DownloadedToByte + (long)this.DEFAULT_CHUNK_SIZE, (Action <HttpStatusCode, long, byte[]>)((statusCode, length, dataBytes) => { if (statusCode == HttpStatusCode.NotFound) { di.LastDownloadResult = DownloadResult.UriNoLongerValid; } else if (length > 0L && dataBytes != null) { CacheManager.TrySaveRawCachedData(dataBytes, di.LocalFileId, FileMode.Append); di.DownloadedToByte += (long)dataBytes.Length; di.Length = length; di.LastDownloadResult = DownloadResult.OK; } else { di.LastDownloadResult = DownloadResult.Failed; } resultCallback(); })); }