Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Video 如何避免在使用windows phone 8应用程序拍摄视频时出现后屏幕_Video_Windows Phone 8 - Fatal编程技术网

Video 如何避免在使用windows phone 8应用程序拍摄视频时出现后屏幕

Video 如何避免在使用windows phone 8应用程序拍摄视频时出现后屏幕,video,windows-phone-8,Video,Windows Phone 8,有时我从windows phone 8应用程序录制视频时会出现黑屏。请任何人帮助我避免黑屏。 这里我运行一个计时器来显示视频的时间。即使我移除计时器,我也会看到黑屏 public void InitializeVideoRecorder() { if (captureSource == null) { // Create the VideoRecorder objects. captureSource = new CaptureSource();

有时我从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();
        });
    }
}
public void InitializeVideoRecorder()
{
如果(captureSource==null)
{
//创建录像机对象。
captureSource=新captureSource();
fileSink=newfilesink();
videoCaptureDevice=CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
int videoformatcount=videoCaptureDevice.SupportedFormats.Count();//我们将获得可用的视频格式
如果(videoformatcount>0)
{
var Temp=videoCaptureDevice.SupportedFormats;
VideoFormat objVideoFormat=Temp[videoformatcount-1];
videoCaptureDevice.DesiredFormat=新的视频格式(PixelFormatType.Format8bpGrayscale,objVideoFormat.PixelWidth,objVideoFormat.PixelHeight,1);
}
captureSource.VideoCaptureDevice=VideoCaptureDevice;
//为captureSource添加事件处理程序。
captureSource.CaptureFailed+=新事件处理程序(OnCaptureFailed);
captureSource.CaptureImageCompleted+=captureSource\u CaptureImageCompleted;
//如果设备上存在摄像头,则初始化摄像头。
if(videoCaptureDevice!=null)
{
//为取景器创建视频画笔。
videoRecorderBrush=新的VideoBrush();
videoRecorderBrush.SetSource(捕获源);
//在矩形上显示取景器图像。
viewfinderRectangle.Fill=videoRecorderBrush;
//启动视频捕获并将其显示在取景器上。
captureSource.Start();
//设置按钮状态和消息。
UpdateUI(ButtonState.Initialized,“点击记录开始记录…”);
}
其他的
{
//当设备不支持摄像头时,禁用按钮。
UpdateUI(ButtonState.CameraNotSupported,“此设备不支持摄像头”);
}
}
}
私有void StartVideoRecording()
{
尝试
{
//将FileLink连接到captureSource。
if(captureSource.VideoCaptureDevice!=null&&captureSource.State==CaptureState.Started)
{
captureSource.Stop();
//连接FileLink的输入和输出。
fileSink.CaptureSource=CaptureSource;
//如果(isoVideoFileName==“”| | isoVideoFileName==null)
isoVideoFileName=rdIMEI+“\u”+设备数据字符串+“\u”+日期时间.Now.ToFileTime().ToString()+”.mp4”;
fileSink.IsolatedStorageFileName=isoVideoFileName;
}
//开始录音。
if(captureSource.VideoCaptureDevice!=null&&captureSource.State==CaptureState.Stopped)
{
//captureSource.CaptureFailed+=captureSource\u CaptureFailed;
captureSource.Start();
captureSource.captureMageAsync();
}
//设置按钮状态和消息。
UpdateUI(ButtonState.Recording,“Recording…”);
}
//如果录制失败,则显示错误。
捕获(例外e)
{
this.Dispatcher.BeginInvoke(委托()
{
//txtDebug.Text=“错误:”+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