Exemple #1
0
        public void CancelVideoDownloading(TLDecryptedMessageMediaVideo mediaVideo)
        {
            mediaVideo.DownloadingProgress = 0.0;

            var fileManager = IoC.Get <IEncryptedFileManager>();

            fileManager.CancelDownloadFile(mediaVideo);
        }
        private void SendVideo(string videoFileName, long duration)
        {
            var chat = Chat as TLEncryptedChat;

            if (chat == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(videoFileName))
            {
                return;
            }

            long size = 0;

            byte[] data;
            using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var file = storage.OpenFile(videoFileName, FileMode.Open, FileAccess.Read))
                {
                    size = file.Length;
                    data = new byte[size];
                    file.Read(data, 0, data.Length);
                }
            }

            byte[] thumb;
            using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var file = storage.OpenFile(videoFileName + ".jpg", FileMode.Open, FileAccess.Read))
                {
                    thumb = new byte[file.Length];
                    file.Read(thumb, 0, thumb.Length);
                }
            }

            var dcId       = TLInt.Random();
            var id         = TLLong.Random();
            var accessHash = TLLong.Random();

            var fileLocation = new TLEncryptedFile
            {
                Id             = id,
                AccessHash     = accessHash,
                DCId           = dcId,
                Size           = new TLInt((int)size),
                KeyFingerprint = new TLInt(0),
                FileName       = new TLString(""),
                Duration       = new TLInt((int)duration)
            };

            var fileName = String.Format("{0}_{1}_{2}.mp4",
                                         fileLocation.Id,
                                         fileLocation.DCId,
                                         fileLocation.AccessHash);

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                store.CopyFile(videoFileName, fileName, true);
                store.DeleteFile(videoFileName);
            }

            var keyIV = GenerateKeyIV();

            int thumbHeight;
            int thumbWidth;

            thumb = ImageUtils.CreateThumb(thumb, Constants.VideoPreviewMaxSize, Constants.VideoPreviewQuality, out thumbHeight, out thumbWidth);

            TLDecryptedMessageMediaVideo decryptedMediaVideo;
            var encryptedChat17 = chat as TLEncryptedChat17;

            if (encryptedChat17 != null)
            {
                decryptedMediaVideo = new TLDecryptedMessageMediaVideo17
                {
                    Thumb    = TLString.FromBigEndianData(thumb),
                    ThumbW   = new TLInt(thumbWidth),
                    ThumbH   = new TLInt(thumbHeight),
                    Duration = new TLInt((int)duration),
                    MimeType = new TLString("video/mp4"),
                    W        = new TLInt(640),
                    H        = new TLInt(480),
                    Size     = new TLInt((int)size),
                    Key      = keyIV.Item1,
                    IV       = keyIV.Item2,

                    File = fileLocation,

                    UploadingProgress = 0.001
                };
            }
            else
            {
                decryptedMediaVideo = new TLDecryptedMessageMediaVideo
                {
                    Thumb    = TLString.FromBigEndianData(thumb),
                    ThumbW   = new TLInt(thumbWidth),
                    ThumbH   = new TLInt(thumbHeight),
                    Duration = new TLInt((int)duration),
                    //MimeType = new TLString("video/mp4"),
                    W    = new TLInt(640),
                    H    = new TLInt(480),
                    Size = new TLInt((int)size),
                    Key  = keyIV.Item1,
                    IV   = keyIV.Item2,

                    File = fileLocation,

                    UploadingProgress = 0.001
                };
            }

            var decryptedTuple = GetDecryptedMessageAndObject(TLString.Empty, decryptedMediaVideo, chat, true);

            Items.Insert(0, decryptedTuple.Item1);
            RaiseScrollToBottom();
            NotifyOfPropertyChange(() => DescriptionVisibility);

            BeginOnThreadPool(() =>
                              CacheService.SyncDecryptedMessage(decryptedTuple.Item1, chat,
                                                                cachedMessage => SendVideoInternal(data, decryptedTuple.Item2)));
        }