Example #1
0
        public PinchAndZoom()
        {
            InitializeComponent();

            media = MediaTransitionHelper.Instance.Media;

            if (media.Constructor == Constructor.messageMediaPhoto)
            {
                ImageViewportElement.Visibility = Visibility.Visible;
                PlaybackControls.Visibility     = Visibility.Collapsed;

                MessageMediaPhotoConstructor cons = (MessageMediaPhotoConstructor)media;

                if (cons.photo.Constructor == Constructor.photoEmpty)
                {
                }
                else if (cons.photo.Constructor == Constructor.photo)
                {
                    PhotoConstructor photoConstructor = (PhotoConstructor)cons.photo;
                    author = TelegramSession.Instance.GetUser(photoConstructor.user_id);
                    MetaInfoAuthor.Text = author.FullName;
                    MetaInfoDate.Text   = Formatters.FormatDialogDateTimestampUnix(photoConstructor.date);
                }

                DoLoadPhoto();
                return;
            }
            else if (media.Constructor == Constructor.messageMediaVideo)
            {
                ImageViewportElement.Visibility = Visibility.Collapsed;
                PlaybackControls.Visibility     = Visibility.Visible;
                VideoPlayerElement.Visibility   = Visibility.Visible;
                PlaybackButton.Visibility       = Visibility.Visible;

                MessageMediaVideoConstructor cons = (MessageMediaVideoConstructor)media;

                if (cons.video.Constructor == Constructor.videoEmpty)
                {
                }
                else if (cons.video.Constructor == Constructor.video)
                {
                    VideoConstructor videoConstructor = (VideoConstructor)cons.video;
                    author = TelegramSession.Instance.GetUser(videoConstructor.user_id);

                    MetaInfoAuthor.Text = author.FullName;
                    MetaInfoDate.Text   = Formatters.FormatDialogDateTimestampUnix(videoConstructor.date);
                }

                VideoPlayerElement.MediaEnded += delegate {
                    PlaybackButton.Visibility = Visibility.Visible;
                };
            }
            else
            {
                return;
            }
        }
Example #2
0
        public async Task <string> DownloadVideo(Video arg, FileUploadProcessHandler handler)
        {
            if (arg.Constructor == Constructor.videoEmpty)
            {
                return(null);
            }

            VideoConstructor video = (VideoConstructor)arg;
            TLApi            api   = await session.GetFileSession(video.dc_id);

            InputFileLocation inputFile     = TL.inputVideoFileLocation(video.id, video.access_hash);
            string            videoPath     = GetVideoPath(video);
            string            tempVideoPath = videoPath + ".tmp";

            int allSize        = video.size;
            int chunkSize      = 128 * 1024;
            int chunksCount    = allSize / chunkSize;
            int lastChunkSize  = allSize - chunkSize * chunksCount;
            int allChunksCount = chunksCount + (lastChunkSize != 0 ? 1 : 0);

            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) {
                if (storage.FileExists(videoPath))
                {
                    return(videoPath);
                }

                using (Stream stream = new IsolatedStorageFileStream(tempVideoPath, FileMode.OpenOrCreate, FileAccess.Write, storage)) {
                    for (int i = 0; i < chunksCount; i++)
                    {
                        handler((float)i * (float)chunkSize / (float)allSize);
                        Upload_fileConstructor chunk = (Upload_fileConstructor)await api.upload_getFile(inputFile, i *chunkSize, chunkSize);

                        stream.Write(chunk.bytes, 0, chunk.bytes.Length);
                    }

                    if (lastChunkSize != 0)
                    {
                        handler((float)chunksCount * (float)chunkSize / (float)allSize);
                        Upload_fileConstructor lastChunk = (Upload_fileConstructor)await api.upload_getFile(inputFile, chunksCount *chunkSize, lastChunkSize);

                        stream.Write(lastChunk.bytes, 0, lastChunk.bytes.Length);
                    }

                    handler(1.0f);
                }

                if (storage.FileExists(videoPath))
                {
                    storage.DeleteFile(videoPath);
                }

                storage.MoveFile(tempVideoPath, videoPath);
            }

            return(videoPath);
        }
Example #3
0
        // nullable
        public static FileLocation FileLocationGetVideoThumbLocation(VideoConstructor video) {
            PhotoSize size = video.thumb;

            if (size.Constructor == Constructor.photoSizeEmpty)
                return null;

            if (size.Constructor == Constructor.photoSize)
                return ((PhotoSizeConstructor) size).location;

            if (size.Constructor == Constructor.photoCachedSize)
                return ((PhotoCachedSizeConstructor) size).location;

            return null;
        }
Example #4
0
        // nullable
        public static FileLocation FileLocationGetVideoThumbLocation(VideoConstructor video)
        {
            PhotoSize size = video.thumb;

            if (size.Constructor == Constructor.photoSizeEmpty)
            {
                return(null);
            }

            if (size.Constructor == Constructor.photoSize)
            {
                return(((PhotoSizeConstructor)size).location);
            }

            if (size.Constructor == Constructor.photoCachedSize)
            {
                return(((PhotoCachedSizeConstructor)size).location);
            }

            return(null);
        }
Example #5
0
//        public async Task<string> DownloadLocation() {
//            new URL("https://maps.googleapis.com/maps/api/staticmap?center=" + geoPoint.getLat() + "," + geoPoint.getLng()
//                    + "&zoom=12&size=" + mapSize + "x" + mapSize + "&sensor=false&markers=color:red|" + geoPoint.getLat() + "," + geoPoint.getLng());
//        }

        private string GetVideoPath(VideoConstructor video)
        {
            return(String.Format("{0}.mp4", video.id));
        }
Example #6
0
//        public async Task<string> DownloadLocation() {
//            new URL("https://maps.googleapis.com/maps/api/staticmap?center=" + geoPoint.getLat() + "," + geoPoint.getLng()
//                    + "&zoom=12&size=" + mapSize + "x" + mapSize + "&sensor=false&markers=color:red|" + geoPoint.getLat() + "," + geoPoint.getLng());
//        }

        private string GetVideoPath(VideoConstructor video) {
            return String.Format("{0}.mp4", video.id);
        }