Exemplo n.º 1
0
        async void OnTakeVideo(object sender, RoutedEventArgs e)
        {
            var op = new CaptureVideoOptions();

            if ((bool)_cbFront.IsChecked)
            {
                op.UseFrontCamera = true;
            }
            if ((bool)_cbSpan.IsChecked)
            {
                op.DesiredLength = TimeSpan.FromSeconds(6);
            }

            var fd = await Kit.TakeVideo(op);

            if (fd != null)
            {
                _mp.Source = MediaSource.CreateFromUri(new Uri(fd.FilePath));
                if (!string.IsNullOrEmpty(fd.ThumbPath))
                {
                    _img.Source = new BitmapImage(new Uri(fd.ThumbPath));
                }
                else
                {
                    _img.Source = null;
                }
            }
            else
            {
                _mp.Source  = null;
                _img.Source = null;
            }
        }
Exemplo n.º 2
0
 public async Task <FileData> TakeVideo(CaptureVideoOptions p_options)
 {
     if (await IsCameraAvailable())
     {
         return(await TakeMedia(false, p_options ?? new CaptureVideoOptions()));
     }
     return(null);
 }
Exemplo n.º 3
0
        public async Task <FileData> TakeVideo(CaptureVideoOptions p_options)
        {
            if (!await IsCameraAvailable())
            {
                return(null);
            }

            var options = p_options ?? new CaptureVideoOptions();
            var capture = new CameraCaptureUI();

            capture.VideoSettings.Format        = CameraCaptureUIVideoFormat.Mp4;
            capture.VideoSettings.MaxResolution = (options.VideoQuality == 1) ? CameraCaptureUIMaxVideoResolution.HighDefinition : CameraCaptureUIMaxVideoResolution.LowDefinition;
            capture.VideoSettings.AllowTrimming = options.AllowCropping;
            if (capture.VideoSettings.AllowTrimming)
            {
                capture.VideoSettings.MaxDurationInSeconds = (float)options.DesiredLength.TotalSeconds;
            }

            var result = await capture.CaptureFileAsync(CameraCaptureUIMode.Video);

            if (result == null)
            {
                return(null);
            }

            // 将文件移动到CachePath
            await result.MoveAsync(await StorageFolder.GetFolderFromPathAsync(Kit.CachePath), Kit.NewGuid + ".mp4");

            var fd   = new FileData(result.Path, result.Name, (await result.GetBasicPropertiesAsync()).Size);
            var prop = await result.Properties.GetVideoPropertiesAsync();

            fd.Desc = string.Format("{0:HH:mm:ss} ({1} x {2})", new DateTime(prop.Duration.Ticks), prop.Width, prop.Height);

            // 生成缩略图
            fd.ThumbPath = Path.Combine(Kit.CachePath, Kit.NewGuid + "-t.jpg");
            using (var fs = File.Create(fd.ThumbPath))
            {
                // 默认根据DPI调整缩略图大小
                var fl = await result.GetThumbnailAsync(ThumbnailMode.SingleItem, FileData.ThumbSize, ThumbnailOptions.ResizeThumbnail);

                await fl.AsStreamForRead().CopyToAsync(fs);
            }
            return(fd);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Launches our own video recording control to capture video
        /// </summary>
        /// <param name="options">may contains additional parameters</param>
        public void captureVideo(string options)
        {
            try
            {
                try
                {
                    this.captureVideoOptions = String.IsNullOrEmpty(options) ?
                                               CaptureVideoOptions.Default : JSON.JsonHelper.Deserialize <CaptureVideoOptions>(options);
                }
                catch (Exception ex)
                {
                    this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message));
                    return;
                }

                videoCaptureTask            = new VideoCaptureTask();
                videoCaptureTask.Completed += videoRecordingTask_Completed;
                videoCaptureTask.Show();
            }
            catch (Exception e)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, e.Message));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Launches our own video recording control to capture video
        /// </summary>
        /// <param name="options">may contains additional parameters</param>
        public void captureVideo(string options)
        {
            try
            {
                try
                {
                    this.captureVideoOptions = String.IsNullOrEmpty(options) ?
                        CaptureVideoOptions.Default : JSON.JsonHelper.Deserialize<CaptureVideoOptions>(options);

                }
                catch (Exception ex)
                {
                    this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message));
                    return;
                }

               videoCaptureTask = new VideoCaptureTask();
               videoCaptureTask.Completed += videoRecordingTask_Completed;
               videoCaptureTask.Show();

            }
            catch (Exception e)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, e.Message));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Launches our own video recording control to capture video
        /// </summary>
        /// <param name="options">may contains additional parameters</param>
        public async void captureVideo(string options)
        {
            try
            {
                try
                {
                    string args = JSON.JsonHelper.Deserialize <string[]>(options)[0];
                    this.captureVideoOptions = String.IsNullOrEmpty(args) ? CaptureVideoOptions.Default : JSON.JsonHelper.Deserialize <CaptureVideoOptions>(args);
                }
                catch (Exception ex)
                {
                    this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message));
                    return;
                }

                cameraTask = new CameraCaptureUI();
                cameraTask.VideoSettings.AllowTrimming = true;
                cameraTask.VideoSettings.Format        = CameraCaptureUIVideoFormat.Mp4;

                StorageFile video = await cameraTask.CaptureFileAsync(CameraCaptureUIMode.Video);

                if (video != null)
                {
                    await video.CopyAsync(Windows.Storage.KnownFolders.VideosLibrary, video.Name, Windows.Storage.NameCollisionOption.GenerateUniqueName);

                    long   size         = 0;
                    string modifiedDate = "";
                    var    tasks        = new List <Task <BasicProperties> >();
                    tasks.Add(video.GetBasicPropertiesAsync().AsTask());
                    var result = await Task.WhenAll(tasks);

                    foreach (var prop in result)
                    {
                        size         = (long)prop.Size;
                        modifiedDate = prop.DateModified.ToString();
                    }

                    MediaFile data = new MediaFile(video.Path, video.ContentType, video.Name, size, modifiedDate);

                    this.files.Add(data);

                    if (files.Count < this.captureVideoOptions.Limit)
                    {
                        //dosomething here
                    }
                    else
                    {
                        DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files));
                        files.Clear();
                    }
                }
                else
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Error in capturing video"));
                }
            }
            catch (Exception ex)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ex.Message));
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// 录像
 /// </summary>
 /// <param name="p_options">选项</param>
 /// <returns>视频文件信息,失败或放弃时返回null</returns>
 public Task <FileData> TakeVideo(CaptureVideoOptions p_options = null)
 {
     return(new CameraCapture().TakeVideo(p_options));
 }