コード例 #1
0
        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 video = new TLVideo
            {
                Id         = new TLLong(0),
                Caption    = new TLString(recorderVideo.FileName),
                AccessHash = new TLLong(0),
                Date       = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now),
                UserId     = new TLInt(StateService.CurrentUserId),
                Duration   = new TLInt((int)recorderVideo.Duration),
                MimeType   = new TLString("video/mp4"),
                Size       = new TLInt((int)size),
                Thumb      = thumbSize,
                DCId       = new TLInt(0),
                W          = new TLInt(640),
                H          = new TLInt(480)
            };

            var media = new TLMessageMediaVideo28
            {
                FileId      = recorderVideo.FileId ?? TLLong.Random(),
                Video       = video,
                IsoFileName = recorderVideo.FileName,
                Caption     = TLString.Empty
            };

            var message = GetMessage(TLString.Empty, media);

            BeginOnUIThread(() =>
            {
                var previousMessage = InsertSendingMessage(message);
                IsEmptyDialog       = Items.Count == 0 && LazyItems.Count == 0;

                BeginOnThreadPool(() =>
                                  CacheService.SyncSendingMessage(
                                      message, previousMessage,
                                      TLUtils.InputPeerToPeer(Peer, StateService.CurrentUserId),
                                      m => SendVideoInternal(message, null)));
            });
        }
コード例 #2
0
        public void SendVideo(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 video = new TLVideo
            {
                Id         = new TLLong(0),
                Caption    = new TLString(Path.GetFileName(file.Name)),
                AccessHash = new TLLong(0),
                Date       = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now),
                UserId     = new TLInt(StateService.CurrentUserId),
                Duration   = new TLInt((int)videoFile.Duration),
                MimeType   = new TLString(file.ContentType),
                Size       = new TLInt((int)videoFile.Size),
                Thumb      = videoFile.ThumbPhoto ?? new TLPhotoSizeEmpty {
                    Type = TLString.Empty
                },
                DCId = new TLInt(0),
                W    = new TLInt((int)videoFile.Width),
                H    = new TLInt((int)videoFile.Height)
            };

            var media = new TLMessageMediaVideo28 {
                Video = video, IsoFileName = file.Path, File = file, Caption = TLString.Empty
            };

            var message = GetMessage(TLString.Empty, media);

            BeginOnUIThread(() =>
            {
                var previousMessage = InsertSendingMessage(message);
                IsEmptyDialog       = Items.Count == 0 && LazyItems.Count == 0;

                BeginOnThreadPool(() =>
                                  CacheService.SyncSendingMessage(
                                      message, previousMessage,
                                      TLUtils.InputPeerToPeer(Peer, StateService.CurrentUserId),
                                      m => SendVideoInternal(message, videoFile)));
            });
        }