简体   繁体   中英

Windows Phone 8.1 Javascript Application - Use Camera

well, I have an existing HTML5 Application which should be ported to Windows Phone 8.1. The existing applications needs some native access for sending mails, writing/reading files to/from the storage and taking pictures.

In my solution I have a Javascript Windows Phone 8.1 Application and a Windows Phone 8.1 Runtime Component. I already managed File/E-Mail Access through the Runtime Component. ( Windows.ApplicationModel.* )

I'm stuck which the Camera. The goal is:

  • Javascript Call "takePicture(callback)"
  • Natively take a picture (How?!)
  • Save it to the storage
  • Execute callback with data/file

I didn't find any real approach yet. How should I do this?

What I tried so far:

public async void takePicture(PhotoSuccessCallback scb, PhotoErrorCallback ecb)
    {
        var x = new MediaCapture();
        var settings = new MediaCaptureInitializationSettings();
        settings.PhotoCaptureSource = PhotoCaptureSource.Photo;
        await x.InitializeAsync(settings);
        await x.StartPreviewAsync();
    }

This code snippet is crashing while StartPreviewAsync() with an unhelpful/generic exception. Just to be clear, I don't really want to do this myself, there has to be an easy solution, right?

If I can't use this code, is it possible to navigate to a other view to manage this?

I have to admit, i'm pretty confused with all this stuff.

Thanks.

Before you can start the preview, you need to assign the MediaCapture as the source to a control that can display your preview.

I believe in JavaScript it would be something along the lines of:

var previewVidTag = document.getElementById("cameraPreview");
var previewUrl = URL.createObjectURL(x);
previewVidTag.src = previewUrl;
previewVidTag.play();

previewVidTag.addEventListener("playing", function () {
    // preview has started
});

And your HTML should have something like this:

<video id="cameraPreview" class="cameraPreview"></video>

I believe you should be able to reference the Windows 10 CameraStarterKit SDK sample to get you started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM