0

I'm pretty new on Windows Phone 8.1 development and what I'm currently trying is recording a video and store it on the Windows Phone. However, I don't have any idea how that can be done. I have some code excerpt below which is the code executed when the start/stop record button is pressed. The code is taken from an example.

My questions:

  1. How _videoFile can be saved to the VideoLibrary?
  2. Preferably I would like the program to execute a method when recording is stopped. How I get the video filename inside this method?

    private async void OnCaptureVideoButtonClick(object sender, RoutedEventArgs e)
    {
        if (!_capturingVideo)
        {
            //BtnStartStop.Content = "Stop";
            StartAppBarButton.Icon = new SymbolIcon(Symbol.Stop);
            _capturingVideo = true;
    
            _videoFile = await TestedControl.StartVideoCaptureAsync(KnownFolders.VideosLibrary, "capture.mp4");
            CapturedVideoElement.Visibility = Visibility.Visible;
    
            IRandomAccessStreamWithContentType stream;
    
            try
            {
                stream = await TryCatchRetry.RunWithDelayAsync<Exception, IRandomAccessStreamWithContentType>(
                    _videoFile.OpenReadAsync(),
                    TimeSpan.FromSeconds(0.5),
                    10);
            }
            catch (Exception ex)
            {
               #pragma warning disable 4014
    
                new MessageDialog(ex.Message, "Error").ShowAsync();
               #pragma warning restore 4014
    
                return;
            }
    
            CapturedVideoElement.SetSource(stream, _videoFile.ContentType);
        }
        else
        {
            StartAppBarButton.Icon = new SymbolIcon(Symbol.Camera);
            _capturingVideo = false;
             #pragma warning disable 4014
            await TestedControl.StopCapture();
    
                #pragma warning restore 4014
        }
    }
    
S P
  • 4,615
  • 2
  • 18
  • 31

1 Answers1

0

Using the await keyword, StartVideoCaptureAsync is called asynchronously. So the next line of code will be executed only once this asynchronous task is finished. It means that the line of code below (and all the next ones):

CapturedVideoElement.Visibility = Visibility.Visible

will be executing at the end of the recording.

So if you need to execute a method after the recording is done, you can just put it after the call of StartVideoCaptureAsync.