mediaCapture在后台任务WP 8.1中工作 [英] mediaCapture work in background task WP 8.1

查看:81
本文介绍了mediaCapture在后台任务WP 8.1中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

面对初始化问题mediaCapture在后台任务中。 API说mediaCapture不支持
的背景,但是我看到了几个实现这个功能的WP 8.1应用程序,只是对冻结屏幕感兴趣。以下是运行应用程序时运行良好的代码


 public async Task Initialize()
{
var cameraId =等待GetCameraId(Panel.Back);
if(cameraId!= null)
{
var settings = new MediaCaptureInitializationSettings
{
VideoDeviceId = cameraId.Id
};

if(this.mediaCapture == null)
{
this.mediaCapture = new MediaCapture();
}

尝试
{
await this.mediaCapture.InitializeAsync(settings);
}
catch(例外){}
this.torchControl = this.mediaCapture?.VideoDeviceController?.TorchControl;
this.IsSupported = this.torchControl!= null&& this.torchControl.Supported;
}
}

public void TurnOn(float powerPercent)
{
if(this.torchControl!= null)
{
if(this.torchControl.PowerSupported)
{
this.torchControl.PowerPercent = powerPercent;
}

this.torchControl.Enabled = true;
SettingsProvider.Instance.IsFlashlightOn = this.torchControl.Enabled;
}
}
private static async任务< DeviceInformation> GetCameraId(Panel desiredCamera)
{
var deviceId = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
返回deviceId?.FirstOrDefault(x => x.EnclosureLocation!= null&& x.EnclosureLocation.Panel == desiredCamera);
}
public void ClearMediaCapture()
{
if(this.torchControl.Enabled)
{
this.TurnOff();
}

this.mediaCapture?.Dispose();
this.mediaCapture = null;
}




查找实现或文章的示例。提前致谢。

解决方案

嗨Dmitiy Yeremenko:


以下是关于M ediaCapture,这是链接:  https://code.msdn.microsoft.com/windowsapps/Media-Capture-Sample-adf87622  ,


这是官方文件:
https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.capture.mediacapture.aspx? F = 255安培; MSPPError = -2147217396&NBSP;
功能;.


我希望这会对你有所帮助。







Faced with the problem of initialization mediaCapture in the background task. The API says that mediaCapture does not support in the background, but I've seen a couple of WP 8.1 applications that implement this functionality, just interested in working with the freezing of the screen. Here is the code that works well when running applications

public async Task Initialize()
{
    var cameraId = await GetCameraId(Panel.Back);
    if(cameraId != null)
    {
        var settings = new MediaCaptureInitializationSettings
        {
            VideoDeviceId = cameraId.Id
        };

        if(this.mediaCapture == null)
        {
            this.mediaCapture = new MediaCapture();
        }

        try
        {
            await this.mediaCapture.InitializeAsync(settings);
        }
        catch(Exception) { }
        this.torchControl = this.mediaCapture?.VideoDeviceController?.TorchControl;
        this.IsSupported = this.torchControl != null && this.torchControl.Supported;
    }
}

public void TurnOn(float powerPercent)
{
    if(this.torchControl != null)
    {
        if(this.torchControl.PowerSupported)
        {
            this.torchControl.PowerPercent = powerPercent;
        }

        this.torchControl.Enabled = true;
        SettingsProvider.Instance.IsFlashlightOn = this.torchControl.Enabled;
    }
}
private static async Task<DeviceInformation> GetCameraId(Panel desiredCamera)
{
    var deviceId = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
    return deviceId?.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredCamera);
}
public void ClearMediaCapture()
{
    if(this.torchControl.Enabled)
    {
        this.TurnOff();
    }

    this.mediaCapture?.Dispose();
    this.mediaCapture = null;
}


Looking for examples of implementation or articles. Thanks in advance.

解决方案

Hi Dmitiy Yeremenko:

Here is the official sample about MediaCapture, here is the link: https://code.msdn.microsoft.com/windowsapps/Media-Capture-Sample-adf87622 ,

here is the official document: https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.capture.mediacapture.aspx?f=255&MSPPError=-2147217396  .

I hope this would help you.





这篇关于mediaCapture在后台任务WP 8.1中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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