如何避免背屏幕时,采取视频窗口手机8应用程序



有时我从windows phone 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();
        });
    }
}

我不知道实际问题是什么,但只需在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

最新更新