(WP8)Flashlight Crashing Bug [英] (WP8) Flashlight Crashing Bug

查看:96
本文介绍了(WP8)Flashlight Crashing Bug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在开发一个手电筒应用程序,我已成功制作一个开/关按钮每隔一个水龙头打开和关闭手电筒。在玩了一下应用程序之后,我意识到如果我去多任务屏幕甚至是
应用程序中的另一个页面,然后返回MainPage(手电筒按钮所在的位置),它会在崩溃时崩溃我试图切换手电筒。

I am developing a flashlight app, and I have successfully made a On/Off button that will turn the flashlight On and Off every other tap. After playing with the app for a bit, I realized that if I go to the multitask screen or even to another page in the app, then return to the MainPage (where the flashlight button is located), it will crash when I attempt to toggle the flashlight.

public async void InitialiseCaptureDevice()
        {
            _captureDevice = await GetCaptureDevice();
            MessageBox.Show("Capture Device Initialized!", "Success", MessageBoxButton.OK);
        }

        public void ToggleFlash()
        {
            const CameraSensorLocation _sensorLocation = CameraSensorLocation.Back;   
            try
            {
                IReadOnlyList<object> supportedCameraModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(_sensorLocation,KnownCameraAudioVideoProperties.VideoTorchMode);

                if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
                {
                    if (!_flashOn)
                    {
                        MessageBox.Show("1");
                        _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
                        MessageBox.Show("2");
                        _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower, AudioVideoCaptureDevice.GetSupportedPropertyRange(_sensorLocation, KnownCameraAudioVideoProperties.VideoTorchPower).Max);
                        MessageBox.Show("3");
                        _flashOn = true;
                    }
                    else
                    {
                        MessageBox.Show("Off1");
                        _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);
                        MessageBox.Show("Off2");
                        _flashOn = false;
                    }
                }
                else
                    MessageBox.Show("Apparently it does not contain UInt32... what a bummer", "Dang It!", MessageBoxButton.OK);
            }
            catch (Exception)
            {
                _flashOn = false;
                InitialiseCaptureDevice();
                ToggleFlash();
                MessageBox.Show("Found Flashlight Error");
            }
        }

        private async Task<AudioVideoCaptureDevice> GetCaptureDevice()
        {
            AudioVideoCaptureDevice captureDevice = await AudioVideoCaptureDevice.OpenAsync(_sensorLocation,AudioVideoCaptureDevice.GetAvailableCaptureResolutions(_sensorLocation).First());
            return captureDevice;
        }

这是我用来编程手电筒的代码。有没有人知道造成这种情况的原因,以及如何解决这个问题?

This is the code I use to program my flashlight. Does anyone have any idea what is causing this, and how it can be fixed?

如果您需要更多信息,请告诉我。

Please let me know if you need more information.

谢谢你,

Sohit P。

PS我发现崩溃发生在MessageBox.Show(" 1");

P.S. I have found that the crash occurs in the line preceding MessageBox.Show("1");

之前的行中。另外,在启动时的其他手电筒应用程序中,亮度会上升,并且如果您转到多任务屏幕,手机的亮度将自动转到您的设置。当你再次打开应用程序时,亮度会再次上升。在我的
应用程序中,亮度会在开始时自动上升,但是当我离开我的应用程序时,亮度会变暗,但是当我回到我的应用程序时。

And also, In other flashlight apps on start, the brightness goes up, and if you go to the multitask screen, the brightness of your phone will automatically go to your settings. When you open the app again, the brightness will go up again. In my app, the brightness will automatically go up at the start, but when I navigate away from my app, the brightness dims, but goes up when I return to my app.

推荐答案

大家好,

我正在开发一个手电筒应用程序,我已经成功地制作了一个开/关按钮,可以在每个其他水龙头上打开和关闭手电筒。在玩了一下应用程序之后,我意识到如果我去多任务屏幕甚至是
应用程序中的另一个页面,然后返回MainPage(手电筒按钮所在的位置),它会在崩溃时崩溃我试图切换手电筒。

I am developing a flashlight app, and I have successfully made a On/Off button that will turn the flashlight On and Off every other tap. After playing with the app for a bit, I realized that if I go to the multitask screen or even to another page in the app, then return to the MainPage (where the flashlight button is located), it will crash when I attempt to toggle the flashlight.

public async void InitialiseCaptureDevice()
        {
            _captureDevice = await GetCaptureDevice();
            MessageBox.Show("Capture Device Initialized!", "Success", MessageBoxButton.OK);
        }

        public void ToggleFlash()
        {
            const CameraSensorLocation _sensorLocation = CameraSensorLocation.Back;   
            try
            {
                IReadOnlyList<object> supportedCameraModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(_sensorLocation,KnownCameraAudioVideoProperties.VideoTorchMode);

                if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
                {
                    if (!_flashOn)
                    {
                        MessageBox.Show("1");
                        _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
                        MessageBox.Show("2");
                        _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower, AudioVideoCaptureDevice.GetSupportedPropertyRange(_sensorLocation, KnownCameraAudioVideoProperties.VideoTorchPower).Max);
                        MessageBox.Show("3");
                        _flashOn = true;
                    }
                    else
                    {
                        MessageBox.Show("Off1");
                        _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);
                        MessageBox.Show("Off2");
                        _flashOn = false;
                    }
                }
                else
                    MessageBox.Show("Apparently it does not contain UInt32... what a bummer", "Dang It!", MessageBoxButton.OK);
            }
            catch (Exception)
            {
                _flashOn = false;
                InitialiseCaptureDevice();
                ToggleFlash();
                MessageBox.Show("Found Flashlight Error");
            }
        }

        private async Task<AudioVideoCaptureDevice> GetCaptureDevice()
        {
            AudioVideoCaptureDevice captureDevice = await AudioVideoCaptureDevice.OpenAsync(_sensorLocation,AudioVideoCaptureDevice.GetAvailableCaptureResolutions(_sensorLocation).First());
            return captureDevice;
        }

这是我用来编程手电筒的代码。有没有人知道造成这种情况的原因,以及如何解决这个问题?

This is the code I use to program my flashlight. Does anyone have any idea what is causing this, and how it can be fixed?

如果您需要更多信息,请告诉我。

Please let me know if you need more information.

谢谢你,

Sohit P。


这篇关于(WP8)Flashlight Crashing Bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆