Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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
Camera 后台任务WP 8.1中的mediaCapture工作_Camera_Windows Phone 8.1_Background Task - Fatal编程技术网

Camera 后台任务WP 8.1中的mediaCapture工作

Camera 后台任务WP 8.1中的mediaCapture工作,camera,windows-phone-8.1,background-task,Camera,Windows Phone 8.1,Background Task,在后台任务中面临初始化mediaCapture的问题。API说mediaCapture在后台不支持,但我见过几个实现此功能的WP 8.1应用程序,只是对冻结屏幕感兴趣。 下面是运行应用程序时运行良好的代码 public async Task Initialize() { var cameraId = await GetCameraId(Panel.Back); if(cameraId != null) { var settings = new MediaC

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

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;
}
公共异步任务初始化()
{
var cameraId=wait GetCameraId(Panel.Back);
if(cameraId!=null)
{
var设置=新的MediaCaptureInitializationSettings
{
VideoDeviceId=cameraId.Id
};
if(this.mediaCapture==null)
{
this.mediaCapture=新的mediaCapture();
}
尝试
{
等待这个.mediaCapture.InitializeAsync(设置);
}
捕获(异常){}
this.torchControl=this.mediaCapture?.VideoDeviceController?.torchControl;
this.IsSupported=this.torchControl!=null&&this.torchControl.Supported;
}
}
公共无效开启(浮动功率百分比)
{
if(this.torchControl!=null)
{
如果(此.torchControl.PowerSupported)
{
this.torchControl.PowerPercent=PowerPercent;
}
this.torchControl.Enabled=true;
SettingsProvider.Instance.IsFlashlightOn=this.torchControl.Enabled;
}
}
专用静态异步任务GetCameraId(面板desiredCamera)
{
var deviceId=等待设备信息.findalsync(DeviceClass.VideoCapture);
返回设备ID?.FirstOrDefault(x=>x.EnclosureLocation!=null&&x.EnclosureLocation.Panel==desiredCamera);
}
public void ClearMediaCapture()
{
如果(此.torchControl.Enabled)
{
这个。关掉();
}
这个.mediaCapture?.Dispose();
this.mediaCapture=null;
}

寻找实现或文章的示例。提前感谢。

您找到在后台任务中使用mediaCaptura的方法了吗?