Krz*_*nek 23 c# deployment camera visual-studio-2013 windows-phone-8.1
我想制作一个简单的应用程序,这将允许我检查每个预览框架的几个参数,但我遇到了运行和停止预览.
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
MediaCapture _MediaCapture;
bool _recording;
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
var rearCamera = devices[0];
if (devices.Count > 0)
{
rearCamera = devices.Single(currDev =>
currDev.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back
);
}
_MediaCapture = new MediaCapture();
await _MediaCapture.InitializeAsync(new MediaCaptureInitializationSettings() { VideoDeviceId = rearCamera.Id });
// this is CaptureElement
xCapture.Source = _MediaCapture;
_recording = false;
}
protected override async void OnNavigatedFrom(NavigationEventArgs e)
{
if(_MediaCapture != null)
{
await _MediaCapture.StopPreviewAsync();
await _MediaCapture.StopRecordAsync();
_MediaCapture.Dispose();
_MediaCapture = null;
xCapture.Source = null;
}
base.OnNavigatedFrom(e);
}
// button click handler
private async void StartMeasure(object sender, RoutedEventArgs e)
{
if (_recording)
{
//await _MediaCapture.StopPreviewAsync();
_MediaCapture.VideoDeviceController.TorchControl.Enabled = false;
_recording = false;
}
else
{
//await _MediaCapture.StartPreviewAsync();
_MediaCapture.VideoDeviceController.TorchControl.Enabled = true;
_recording = true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这种形式下,它完美地运作.
如果我取消注释那些预览行,它只能运行一次.
如果我按下按钮三次:打开,关闭和再次打开我在启用TorchControl时会出现异常.
System.Exception:来自HRESULT的异常:位于Pulsometr3.MainPage.d__d.MoveNext()的Windows.Media.Devices.TorchControl.put_Enabled(布尔值)的0xE801000D
HRESULT各不相同.
更奇怪的是,它有时会冻结手机(比如3次中的2次),我需要按住Power + Volume Down.
我尝试使用[STAThread]装饰所有方法,但它没有帮助(http://technet.microsoft.com/en-ca/br226599).
更有趣的是,当我通过debbuger使用F10执行操作来跨越线路时,我可以根据需要多次切换预览.这很糟糕,因为调试器拥有所有线程,对吗?所以理论上没有区别?
此外,手机有时会冻结部署...而这只是令人讨厌.
有任何想法吗?
我对此很感兴趣……出于某种原因,微软不太关心它的 WP8 后继操作系统,这让我真的很难过。但这也是半年前的夏天,我尝试过这个,也许你可以尝试谷歌搜索应用程序同意,并仔细检查你的应用程序清单,如果你勾选了前置/后置摄像头和网络摄像头:)此外如果它不起作用,那么运气不好,你应该坚持使用 wp 8.0 版本,它在 wp 8.1 上的工作原理完全相同,所以不用担心:)其他库,如 facebook stuff 或 parse.com 也将无法工作在 wp 8.1 C# 上:)
| 归档时间: |
|
| 查看次数: |
1488 次 |
| 最近记录: |