2014-11-02 56 views
1

有时我越来越黑屏,同时从我的Windows Phone 8应用程序录制视频。请你帮助我,以避免黑屏。 这里我正在运行一个计时器来显示视频的时间。即使我删除计时器也是我得到了黑屏。如何避免在视频窗口时背屏幕电话8应用程序

public void InitializeVideoRecorder() 
{ 

    if (captureSource == null) 
    { 
     // Create the VideoRecorder objects. 
     captureSource = new CaptureSource(); 
     fileSink = new FileSink(); 

     videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); 

     int videoformatcount = videoCaptureDevice.SupportedFormats.Count(); //We will get the avilable video format 

     if (videoformatcount > 0) 
     { 
      var Temp = videoCaptureDevice.SupportedFormats; 

      VideoFormat objVideoFormat = Temp[videoformatcount - 1]; 

      videoCaptureDevice.DesiredFormat = new VideoFormat(PixelFormatType.Format8bppGrayscale, objVideoFormat.PixelWidth, objVideoFormat.PixelHeight, 1); 
     } 

     captureSource.VideoCaptureDevice = videoCaptureDevice; 

     // Add eventhandlers for captureSource. 
     captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed); 
     captureSource.CaptureImageCompleted += captureSource_CaptureImageCompleted; 
     // Initialize the camera if it exists on the device. 
     if (videoCaptureDevice != null) 
     { 
      // Create the VideoBrush for the viewfinder. 
      videoRecorderBrush = new VideoBrush(); 
      videoRecorderBrush.SetSource(captureSource); 

      // Display the viewfinder image on the rectangle. 
      viewfinderRectangle.Fill = videoRecorderBrush; 

      // Start video capture and display it on the viewfinder. 
      captureSource.Start(); 


      // Set the button state and the message. 
      UpdateUI(ButtonState.Initialized, "Tap record to start recording..."); 
     } 
     else 
     { 
      // Disable buttons when the camera is not supported by the device. 
      UpdateUI(ButtonState.CameraNotSupported, "Camera is not supported on this device."); 
     } 
    } 

} 

private void StartVideoRecording() 
{ 
    try 
    { 
     // Connect fileSink to captureSource. 
     if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Started) 
     { 
      captureSource.Stop(); 

      // Connect the input and output of fileSink. 
      fileSink.CaptureSource = captureSource; 

      //if (isoVideoFileName == "" || isoVideoFileName == null) 
      isoVideoFileName = rdIMEI + "_" + DeviceIDAsString + "_" + DateTime.Now.ToFileTime().ToString() + ".mp4"; 
      fileSink.IsolatedStorageFileName = isoVideoFileName; 
     } 

     // Begin recording. 
     if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Stopped) 
     { 
      // captureSource.CaptureFailed += captureSource_CaptureFailed; 
      captureSource.Start(); 
      captureSource.CaptureImageAsync(); 
     } 

     // Set the button states and the message. 
     UpdateUI(ButtonState.Recording, "Recording..."); 
    } 

    // If recording fails, display an error. 
    catch (Exception e) 
    { 
     this.Dispatcher.BeginInvoke(delegate() 
     { 
      //txtDebug.Text = "ERROR: " + e.Message.ToString(); 
     }); 
    } 
} 

回答

1

我不知道什么是真正的问题,但你可以解决它只是在你的startvideorecording方法再次创造CaptureSource。

 captureSource = new CaptureSource(); // created again to avoid blank screen bug 
     captureSource.VideoCaptureDevice = videoCaptureDevice; 

     // Connect the input and output of fileSink. 
     fileSink.CaptureSource = captureSource; 

     //if (isoVideoFileName == "" || isoVideoFileName == null) 
     isoVideoFileName = rdIMEI + "_" + DeviceIDAsString + "_" + DateTime.Now.ToFileTime().ToString() + ".mp4"; 
     fileSink.IsolatedStorageFileName = isoVideoFileName; 

     videoRecorderBrush.SetSource(captureSource); // set capture source again since it's changed 
+0

它正在工作..非常感谢.. ..! – user3056216 2014-11-06 10:01:20

相关问题