Exemplo n.º 1
0
        /// <summary>
        /// Handles result of video recording tasks
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">stores information about current captured video</param>
        private void videoRecordingTask_Completed(object sender, VideoResult e)
        {
            if (e.Error != null)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
                return;
            }

            switch (e.TaskResult)
            {
            case TaskResult.OK:
                try
                {
                    // Get image data
                    MediaFile data = new MediaFile(e.VideoFileName, e.VideoFile);

                    this.files.Add(data);

                    if (files.Count < this.captureVideoOptions.Limit)
                    {
                        videoCaptureTask.Show();
                    }
                    else
                    {
                        DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files));
                        files.Clear();
                    }
                }
                catch (Exception)
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Error capturing video."));
                }
                break;

            case TaskResult.Cancel:
                if (files.Count > 0)
                {
                    // User canceled operation, but some video clips were made
                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files));
                    files.Clear();
                }
                else
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Canceled."));
                }
                break;

            default:
                if (files.Count > 0)
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files));
                    files.Clear();
                }
                else
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Did not complete!"));
                }
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resaves video clip from temporary directory to persistent
        /// </summary>
        private VideoResult SaveVideoClip()
        {
            try
            {
                using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (string.IsNullOrEmpty(filePath) || (!isoFile.FileExists(filePath)))
                    {
                        return(new VideoResult(TaskResult.Cancel));
                    }

                    string fileName = String.Format(FileNameFormat, Guid.NewGuid().ToString());
                    string newPath  = Path.Combine("/" + LocalFolderName + "/", fileName);
                    isoFile.CopyFile(filePath, newPath);
                    isoFile.DeleteFile(filePath);

                    memoryStream = new MemoryStream();
                    using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(newPath, FileMode.Open, isoFile))
                    {
                        fileStream.CopyTo(memoryStream);
                    }

                    VideoResult result = new VideoResult(TaskResult.OK);
                    result.VideoFileName = newPath;
                    result.VideoFile     = this.memoryStream;
                    result.VideoFile.Seek(0, SeekOrigin.Begin);
                    return(result);
                }
            }
            catch (Exception)
            {
                return(new VideoResult(TaskResult.None));
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Sets the recording state: display the video on the viewfinder.
 /// </summary>
 private void StartVideoPreview()
 {
     try
     {
         if ((captureSource.VideoCaptureDevice != null) && (captureSource.State == CaptureState.Stopped))
         {
             videoRecorderBrush.SetSource(captureSource);
             viewfinderRectangle.Fill = videoRecorderBrush;
             captureSource.Start();
             this.UpdateUI(VideoState.Ready);
         }
     }
     catch (Exception)
     {
         this.result = new VideoResult(TaskResult.None);
         this.NavigateBack();
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Sets the recording state: stop recording
 /// </summary>
 private void StopVideoRecording()
 {
     try
     {
         if ((captureSource.VideoCaptureDevice != null) && (captureSource.State == CaptureState.Started))
         {
             captureSource.Stop();
             fileSink.CaptureSource           = null;
             fileSink.IsolatedStorageFileName = null;
             this.StartVideoPreview();
         }
     }
     catch (Exception)
     {
         this.result = new VideoResult(TaskResult.None);
         this.NavigateBack();
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Sets recording state: start recording
        /// </summary>
        private void StartVideoRecording()
        {
            try
            {
                if ((captureSource.VideoCaptureDevice != null) && (captureSource.State == CaptureState.Started))
                {
                    captureSource.Stop();
                    fileSink.CaptureSource = captureSource;
                    filePath = System.IO.Path.Combine("/" + LocalFolderName + "/", defaultFileName);

                    using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        if (!isoFile.DirectoryExists(LocalFolderName))
                        {
                            isoFile.CreateDirectory(LocalFolderName);
                        }

                        if (isoFile.FileExists(filePath))
                        {
                            isoFile.DeleteFile(filePath);
                        }
                    }

                    fileSink.IsolatedStorageFileName = filePath;
                }

                if (captureSource.VideoCaptureDevice != null &&
                    captureSource.State == CaptureState.Stopped)
                {
                    captureSource.Start();
                }
                this.UpdateUI(VideoState.Recording);
            }
            catch (Exception)
            {
                this.result = new VideoResult(TaskResult.None);
                this.NavigateBack();
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Handles TakeVideo button click
 /// </summary>
 private void TakeVideo_Click(object sender, EventArgs e)
 {
     this.result = this.SaveVideoClip();
     this.NavigateBack();
 }
Exemplo n.º 7
0
 /// <summary>
 /// Sets the recording state: stop recording
 /// </summary>
 private void StopVideoRecording()
 {
     try
     {
         if ((captureSource.VideoCaptureDevice != null) && (captureSource.State == CaptureState.Started))
         {
             captureSource.Stop();
             fileSink.CaptureSource = null;
             fileSink.IsolatedStorageFileName = null;
             this.StartVideoPreview();
         }
     }
     catch (Exception)
     {
         this.result = new VideoResult(TaskResult.None);
         this.NavigateBack();
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Sets recording state: start recording 
        /// </summary>
        private void StartVideoRecording()
        {
            try
            {
                if ((captureSource.VideoCaptureDevice != null) && (captureSource.State == CaptureState.Started))
                {
                    captureSource.Stop();
                    fileSink.CaptureSource = captureSource;
                    filePath = System.IO.Path.Combine("/" + LocalFolderName + "/", defaultFileName);

                    using(IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        if (!isoFile.DirectoryExists(LocalFolderName))
                        {
                            isoFile.CreateDirectory(LocalFolderName);
                        }

                        if (isoFile.FileExists(filePath))
                        {
                            isoFile.DeleteFile(filePath);
                        }
                    }

                    fileSink.IsolatedStorageFileName = filePath;
                }

                if (captureSource.VideoCaptureDevice != null
                    && captureSource.State == CaptureState.Stopped)
                {
                    captureSource.Start();
                }
                this.UpdateUI(VideoState.Recording);
            }
            catch (Exception)
            {
                this.result = new VideoResult(TaskResult.None);
                this.NavigateBack();
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Sets the recording state: display the video on the viewfinder. 
 /// </summary>
 private void StartVideoPreview()
 {
     try
     {
         if ((captureSource.VideoCaptureDevice != null) && (captureSource.State == CaptureState.Stopped))
         {
             videoRecorderBrush.SetSource(captureSource);
             viewfinderRectangle.Fill = videoRecorderBrush;
             captureSource.Start();
             this.UpdateUI(VideoState.Ready);
         }
     }
     catch (Exception)
     {
         this.result = new VideoResult(TaskResult.None);
         this.NavigateBack();
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Resaves video clip from temporary directory to persistent 
        /// </summary>
        private VideoResult SaveVideoClip()
        {
            try
            {
                using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (string.IsNullOrEmpty(filePath) || (!isoFile.FileExists(filePath)))
                    {
                        return new VideoResult(TaskResult.Cancel);
                    }

                    string fileName = String.Format(FileNameFormat, Guid.NewGuid().ToString());
                    string newPath = Path.Combine("/" + LocalFolderName + "/", fileName);
                    isoFile.CopyFile(filePath,newPath);
                    isoFile.DeleteFile(filePath);

                    memoryStream = new MemoryStream();
                    using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(newPath,FileMode.Open,isoFile))
                    {
                        fileStream.CopyTo(memoryStream);
                    }

                    VideoResult result = new VideoResult(TaskResult.OK);
                    result.VideoFileName = newPath;
                    result.VideoFile = this.memoryStream;
                    result.VideoFile.Seek(0, SeekOrigin.Begin);
                    return result;
                }

            }
            catch (Exception)
            {
                return new VideoResult(TaskResult.None);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Handles result of video recording tasks 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">stores information about current captured video</param>
        private void videoRecordingTask_Completed(object sender, VideoResult e)
        {
            if (e.Error != null)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
                return;
            }

            switch (e.TaskResult)
            {
                case TaskResult.OK:
                    try
                    {
                        // Get image data
                        MediaFile data = new MediaFile(e.VideoFileName, e.VideoFile);

                        this.files.Add(data);

                        if (files.Count < this.captureVideoOptions.Limit)
                        {
                            videoCaptureTask.Show();
                        }
                        else
                        {
                            DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files));
                            files.Clear();
                        }
                    }
                    catch (Exception)
                    {
                        DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Error capturing video."));
                    }
                    break;

                case TaskResult.Cancel:
                    if (files.Count > 0)
                    {
                        // User canceled operation, but some video clips were made
                        DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files));
                        files.Clear();
                    }
                    else
                    {
                        DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Canceled."));
                    }
                    break;

                default:
                    if (files.Count > 0)
                    {
                        DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files));
                        files.Clear();
                    }
                    else
                    {
                        DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Did not complete!"));
                    }
                    break;
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Handles TakeVideo button click
 /// </summary>
 private void TakeVideo_Click(object sender, EventArgs e)
 {
     this.result = this.SaveVideoClip();
     this.NavigateBack();
 }