public async Task SendLocalVideoAsync(YVideo video, VideoStreamInfo videoStream, string path) { if (video == null) { throw new ArgumentNullException("video"); } if (videoStream == null) { throw new ArgumentNullException("videoStream"); } if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } FileInfo file = new FileInfo(path); if (!file.Exists) { throw new Exception(string.Format("Файл по адресу {0} не найден", path)); } TLAbsInputFile fileResult = this.UploadLocalFileToTelegram(path, video.Title); string mimeType = "video/mp4"; TLDocumentAttributeVideo attr1 = new TLDocumentAttributeVideo() { Duration = (int)video.Duration.TotalSeconds + 1, H = videoStream.Resolution.Height, W = videoStream.Resolution.Width, }; TLVector <TLAbsDocumentAttribute> attrs = new TLVector <TLAbsDocumentAttribute>(); attrs.Add(attr1); TLInputPeerUser peer = new TLInputPeerUser() { UserId = this.CurrentAuthUser.Id }; var sendTask = this.TClient.SendUploadedDocument( peer, fileResult, video.Title, mimeType, attrs); sendTask.Wait(); }
public static double GetGifDimension(double maxGifDimension, IPhotoSize thumb, IAttributes attributes, bool isWidth) { TLDocumentAttributeVideo videoAttribute = null; if (attributes != null) { for (var i = 0; i < attributes.Attributes.Count; i++) { videoAttribute = attributes.Attributes[i] as TLDocumentAttributeVideo; if (videoAttribute != null) { break; } } } if (videoAttribute != null) { var width = videoAttribute.W.Value; var height = videoAttribute.H.Value; var maxDimension = width; if (maxDimension > 0) { var scaleFactor = maxGifDimension / maxDimension; return(isWidth ? scaleFactor * width : scaleFactor *height); } } if (thumb != null) { var width = thumb.W.Value; var height = thumb.H.Value; var maxDimension = width; if (maxDimension > 0) { var scaleFactor = maxGifDimension / maxDimension; return(isWidth ? scaleFactor * width : scaleFactor *height); } } return(maxGifDimension); }
private void SendVideo(RecordedVideo recorderVideo) { if (recorderVideo == null) { return; } long size = 0; using (var storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var file = storage.OpenFile(recorderVideo.FileName, FileMode.Open, FileAccess.Read)) { size = file.Length; } } long photoSize = 0; using (var storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var file = storage.OpenFile(recorderVideo.FileName + ".jpg", FileMode.Open, FileAccess.Read)) { photoSize = file.Length; } } var volumeId = TLLong.Random(); var localId = TLInt.Random(); var secret = TLLong.Random(); var thumbLocation = new TLFileLocation //TODO: replace with TLFileLocationUnavailable { DCId = new TLInt(0), VolumeId = volumeId, LocalId = localId, Secret = secret, }; var fileName = String.Format("{0}_{1}_{2}.jpg", thumbLocation.VolumeId, thumbLocation.LocalId, thumbLocation.Secret); // заменяем имя на стандартное для всех каритинок using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { store.CopyFile(recorderVideo.FileName + ".jpg", fileName, true); store.DeleteFile(recorderVideo.FileName + ".jpg"); } var thumbSize = new TLPhotoSize { W = new TLInt(640), H = new TLInt(480), Size = new TLInt((int)photoSize), Type = new TLString(""), Location = thumbLocation, }; var documentAttributeVideo = new TLDocumentAttributeVideo { Duration = new TLInt((int)recorderVideo.Duration), W = new TLInt(640), H = new TLInt(480) }; var document = new TLDocument54 { Id = new TLLong(0), AccessHash = new TLLong(0), Date = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now), MimeType = new TLString("video/mp4"), Size = new TLInt((int)size), Thumb = thumbSize, DCId = new TLInt(0), Version = new TLInt(0), Attributes = new TLVector <TLDocumentAttributeBase> { documentAttributeVideo } }; var media = new TLMessageMediaDocument75 { Flags = new TLInt(0), FileId = recorderVideo.FileId ?? TLLong.Random(), Document = document, IsoFileName = recorderVideo.FileName, Caption = TLString.Empty }; var message = GetMessage(TLString.Empty, media); BeginOnUIThread(() => { var previousMessage = InsertSendingMessage(message); IsEmptyDialog = Items.Count == 0 && (_messages == null || _messages.Count == 0) && LazyItems.Count == 0; BeginOnThreadPool(() => CacheService.SyncSendingMessage( message, previousMessage, m => SendVideoInternal(message, null))); }); }
public void ContinueSendVideo(CompressingVideoFile videoFile) { if (videoFile == null) { return; } var file = videoFile.Source; if (file == null) { return; } if (!CheckDocumentSize(videoFile.Size)) { MessageBox.Show( string.Format(AppResources.MaximumFileSizeExceeded, MediaSizeConverter.Convert((int)Telegram.Api.Constants.MaximumUploadedFileSize)), AppResources.Error, MessageBoxButton.OK); return; } // to get access to the file with StorageFile.GetFileFromPathAsync in future AddFileToFutureAccessList(file); var documentAttributeVideo = new TLDocumentAttributeVideo { Duration = new TLInt((int)videoFile.Duration), W = new TLInt((int)videoFile.Width), H = new TLInt((int)videoFile.Height) }; var documentAttributeFileName = new TLDocumentAttributeFileName { FileName = new TLString(file.Name) }; var document = new TLDocument54 { Id = TLLong.Random(), AccessHash = new TLLong(0), Date = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now), MimeType = new TLString(file.ContentType), Size = new TLInt((int)videoFile.Size), Thumb = videoFile.ThumbPhoto ?? new TLPhotoSizeEmpty { Type = TLString.Empty }, DCId = new TLInt(0), Version = new TLInt(0), Attributes = new TLVector <TLDocumentAttributeBase> { documentAttributeFileName, documentAttributeVideo } }; if (videoFile.EncodingProfile != null && videoFile.EncodingProfile.Audio == null && videoFile.Size < Telegram.Api.Constants.GifMaxSize && TLString.Equals(document.MimeType, new TLString("video/mp4"), StringComparison.OrdinalIgnoreCase)) { document.Attributes.Add(new TLDocumentAttributeAnimated()); } var media = new TLMessageMediaDocument75 { Flags = new TLInt(0), Document = document, IsoFileName = file.Path, File = file, Caption = TLString.Empty }; var caption = string.IsNullOrEmpty(videoFile.Caption) ? TLString.Empty : new TLString(videoFile.Caption); var message = GetMessage(caption, media); if (videoFile.TimerSpan != null && videoFile.TimerSpan.Seconds > 0) { message.NotListened = true; var ttlMessageMedia = message.Media as ITTLMessageMedia; if (ttlMessageMedia != null) { ttlMessageMedia.TTLSeconds = new TLInt(videoFile.TimerSpan.Seconds); } } _mentions = videoFile.Mentions; var processedText = string.Empty; var entities = GetEntities(message.Message.ToString(), out processedText); _mentions = null; if (entities.Count > 0) { message.Message = new TLString(processedText); message.Entities = new TLVector <TLMessageEntityBase>(entities); } BeginOnUIThread(() => { var previousMessage = InsertSendingMessage(message); IsEmptyDialog = Items.Count == 0 && (_messages == null || _messages.Count == 0) && LazyItems.Count == 0; BeginOnThreadPool(() => CacheService.SyncSendingMessage( message, previousMessage, m => SendVideoInternal(message, videoFile))); }); }