示例#1
0
        /// <summary>
        /// Capture a lot of bitmaps and convert them to video.
        /// </summary>
        /// <param name="region"></param>
        /// <param name="offset"></param>
        public async void CaptureVideo(Rectangle region, Point offset)
        {
            MemoryStream stream;
            var          toast = -1;

            // Create a new toast which closing event gonna stop the recording
            toast = ToastService.Create(Resources.StopRecording, Color.OrangeRed, 0, () =>
            {
                toast = ToastService.Create(Resources.Encoding, 0);
                CaptureService.StopRecording();
            });

            // Use Mpeg if enabled
            if (ConfigService.Current.EnableMpeg)
            {
                stream = await CaptureService.RecordMpeg(region, offset);
            }
            else
            {
                stream = await CaptureService.RecordGif(region, offset);
            }

            ToastService.Remove(toast);

            // Generate filename and start the upload(s)
            var url = await UploadAll(stream, ConfigService.Current.EnableMpeg? "mp4" : "gif");

            stream.Dispose();

            CopyUrl(url);
            Complete(url != null); // Exits the application
        }
示例#2
0
        /// <summary>
        /// Upload the given stream with all loaded providers.
        /// </summary>
        /// <param name="ext"></param>
        /// <param name="stream"></param>
        /// <returns></returns>
        private async Task <string> UploadAll(MemoryStream stream, string ext)
        {
            var name  = $"{DateTime.Now:yyyy_MM_dd_HH_mm_ss}.{ext}";
            var toast = ToastService.Create(string.Format(Resources.Uploading, $"{(double)stream.Length / (1024 * 1024):0.00} MB"), 0);

            // Try to load the saved providers (if load on startup is disabled)
            if (!ConfigService.Current.StartupRegister)
            {
                await RestoreProviders();
            }

            // Save file locally if no providers were registered
            if (ProviderService.RegisteredProviders.Count == 0)
            {
                File.WriteAllBytes(name, stream.ToArray());
                ToastService.Remove(toast);
                return(null);
            }

            var uploads = new Dictionary <string, Task <string> >();

            string result = null;
            string last   = null;

            // Run the uploads async
            foreach (var p in ProviderService.RegisteredProviders)
            {
                if (p.Value != null)
                {
                    uploads[p.Key] = p.Value.Upload(name, stream);
                }
            }

            // Wait for the uploads to finish and get the chosen URL
            foreach (var p in uploads)
            {
                var url = await p.Value;

                if (string.IsNullOrEmpty(url))
                {
                    ToastService.Remove(toast);
                    ToastService.Create(string.Format(Resources.ProviderUploadFailed, p.Key));
                }
                else
                {
                    last = url;

                    if (p.Key == ConfigService.Current.CopyProvider)
                    {
                        result = url;
                    }
                }
            }

            ToastService.Remove(toast);

            // If the chosen URL was not found (or null), use the URL of the last successful one
            return(string.IsNullOrEmpty(result) ? last : result);
        }
示例#3
0
        /// <summary>
        /// Capture a lot of bitmaps and convert them to video.
        /// </summary>
        /// <param name="region"></param>
        public async void CaptureVideo(Rectangle region)
        {
            MemoryStream stream;
            var          toast = -1;

            // Create a new toast which closing event gonna stop the recording
            toast = ToastService.Create(Resources.StopRecording, Color.OrangeRed, 0, () =>
            {
                toast = ToastService.Create(Resources.Encoding, 0);
                CaptureService.StopRecording();
            });

            stream = await CaptureService.RecordVideo(region, Config.VideoExt, SettingsService.Current.SafeVideoFps);

            ToastService.Remove(toast);

            // Generate filename and start the upload(s)
            var url = await UploadAll(stream, Config.VideoExt);

            stream.Dispose();

            CopyUrl(url);
            Complete(url != null); // Exits the application
        }