如何在拍摄视频windows phone 8 app时避免背面屏幕

时间:2014-11-02 13:20:05

标签: video windows-phone-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();
        });
    }
}

1 个答案:

答案 0 :(得分: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