locked
MediaCapture: methods missing not mentioned on the docs?

    Question

  • Hello guys.

    Some questions regarding the CameraCapture classe:

    1. I've run a search in the migration docs and couldn't find any mention about the removal of the startPreviewAsync method (http://msdn.microsoft.com/en-us/library/windows/apps/windows.media.capture.mediacapture.startpreviewasync.aspx)- I'm assuming that the only way to get a preview is to record the capture and pass that MediaCapture object to a video element. Am I wrong?

    2. In my tests, the setPreviewMirroring does nothing visible. Here's the code I'm using to reproduce the feed received from ther web cam:

    function iniciaCaptura() {
            document.getElementById("terminar").disabled = !(document.getElementById("iniciar").disabled = true);        
            captura = new Windows.Media.Capture.MediaCapture();
            
            captura.initializeAsync(definicoes)
                .done(function (resultado) {
                    //configurar captura para gravar imagem com captura de 90 graus
                    //captura.setRecordRotation(Windows.Media.Capture.VideoRotation.clockwise90Degrees);
                                  
                    
                    inicializaSliders();
                    //efetuar rotação de 90 graus do preview
                    //captura.setPreviewRotation(Windows.Media.Capture.VideoRotation.clockwise90Degrees);
                    video.src = URL.createObjectURL(captura,false);
                    video.play();                
                    Windows.Storage.KnownFolders.videosLibrary.createFileAsync("livro.mp4",
                        Windows.Storage.CreationCollisionOption.replaceExisting)
                    .done(function (storageItem) {
                        ficheiro = storageItem;
                        var perfil = criaPerfil();
                        captura.startRecordToStorageFileAsync(perfil, ficheiro);
                    });
                });
        }

    To flip the video, I had to use the msHorizontalMIrror property of the video element. It does produce the result, but I'm assuming that 1.) my code is wrong or 2.) this setPreviewMirroring does not work anymore because there's no longer a startPreviewAsync method? Any other ideas?

    thanks.


    Luis Abreu

    Saturday, May 12, 2012 2:21 PM

Answers

  • These should work and should all be available from JavaScript. Windows Runtime classes such as Windows.Media.Capture.MediaCapture have a single implementation which is projected to all languages equally.

    The documentation isn't complete for the Consumer Preview and so some articles (like the one you linked) are available only for Xaml or only for HTML, but the underlying code is available to everybody and can be called with just the language being translated.

    That said, the quickstart you mention includes JavaScript sample code, but not C#/VB/C++ sample code.

    Are you having trouble getting that sample code to work? Can you explain the problem you are running into more clearly?

    --Rob

     

    Wednesday, May 16, 2012 10:09 PM
    Owner

All replies

  • StartPreviewAsync still exists. Why do you think it was removed?

    The Media capture using webcam sample and Camera Capture UI samples both demonstrate it (although not in JavaScript, but other than the syntax changes the same API is used in all languages).

    --Rob

    Saturday, May 12, 2012 5:23 PM
    Owner
  • Well, I'm using JavaScript and I guess that's why I think it doesn't exist :)

    NOw that you said it still existed, I went to the docs and noticed that it doesn't have the JavaScript tab...

    btw, I've asked about it because it appears in the quickstart sample shown here http://msdn.microsoft.com/en-us/library/windows/apps/hh452781.aspx. However, not startPreviewAsync, not stopPreviewASync seem to be available from JavaScript...

    btw, any comments regarding the setPreviewMirroring?

    thanks.


    Luis Abreu

    Saturday, May 12, 2012 6:15 PM
  • Bump?

    any comments on the setPreviewMirroring method? does it work?


    Luis Abreu

    Wednesday, May 16, 2012 9:38 AM
  • These should work and should all be available from JavaScript. Windows Runtime classes such as Windows.Media.Capture.MediaCapture have a single implementation which is projected to all languages equally.

    The documentation isn't complete for the Consumer Preview and so some articles (like the one you linked) are available only for Xaml or only for HTML, but the underlying code is available to everybody and can be called with just the language being translated.

    That said, the quickstart you mention includes JavaScript sample code, but not C#/VB/C++ sample code.

    Are you having trouble getting that sample code to work? Can you explain the problem you are running into more clearly?

    --Rob

     

    Wednesday, May 16, 2012 10:09 PM
    Owner
  • Hell again Rob.

    Regarding question 1, there's no problem because the startPreviewAsync is not  available in JavaScript. in this case, the docs about the method are correct, but this quickstart (http://msdn.microsoft.com/en-us/library/windows/apps/hh452781.aspx) isn't (notice that the sample uses the startPreviewAsync method from JavaScript when that method isn't projected in this language).

    That leaves us with question 2: setPreviewMirroring. That method does exist, but I'm having some trouble making it work. Once again, here's the code I've tried using to mirror the video:

    function alteraMirroring() {
            //captura references a MediaCapture object
            //which has been initialized and is used to feed a video element in the page
           if (!captura) return;
           //nothing happens
           captura.setPreviewMirroring(document.getElementById("mirror").checked);

           //the msHorizontalMirror attribute does work!
           //video.msHorizontalMirror = document.getElementById("mirror").checked;

        }

    And here's the code responsible for starting the capture and reproducing it in the video element

    function iniciaCaptura() {
            document.getElementById("terminar").disabled = !(document.getElementById("iniciar").disabled = true);        
            captura = new Windows.Media.Capture.MediaCapture();
            
            captura.initializeAsync(definicoes)
                .done(function (resultado) {
                    inicializaSliders();
                    video.src = URL.createObjectURL(captura,false);
                    video.play();                
                    Windows.Storage.KnownFolders.videosLibrary.createFileAsync("livro.mp4",
                        Windows.Storage.CreationCollisionOption.replaceExisting)
                    .done(function (storageItem) {
                        ficheiro = storageItem;
                        var perfil = criaPerfil();
                        captura.startRecordToStorageFileAsync(perfil, ficheiro);
                    });
                });
        }

    Bottom line: can't mirror the video using the setPreviewMirror method (btw, I've also tried setting it before getting the URL used for feeding the video element). Can only mirror it by using the msHorizontalMirror prop of the video element. And that's why I'm asking if setPreviewMirror is supposed to be used in JS...

    thanks


    Luis Abreu

    Thursday, May 17, 2012 9:02 AM
  • Hello Luis,

    "setPreviewMirror" should work as expected from JavaScript. Can you do me a favor and try the "setPreviewRotation" method? This will help us determine if we have missed somthing here.

    Thanks,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Friday, May 18, 2012 9:32 PM
    Moderator
  • Hello James.

    That one and the setRecordRotation do work as expected. The only one which didn't do anything in the machines I've tested was the setPreviewMirror. I think the previous snippet I've send you shoudl be enough to understand what's going on. the idea is to have a checkbox and handle its checked event in order to mirror it. As I said, I've also tried mirroring it before passing the stream to the video element, but it still didn't work.

    thanks again.


    Luis Abreu

    Friday, May 18, 2012 9:43 PM
  • Thanks Luis, this is not the expected behavior. I will pass this along.

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Friday, May 18, 2012 9:53 PM
    Moderator
  • Thanks James.

    Please let me know if the problem is with my code.


    Luis Abreu

    Friday, May 18, 2012 10:06 PM
  • Hello,

    You can use this however in your javascript or set this property on your <video> tag in HTML ( http://msdn.microsoft.com/en-us/library/windows/apps/hh452783(v=vs.85).aspx ):
    msHorizontalMirror= true;

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, May 24, 2012 11:31 AM
    Moderator
  • Hello Jesse,

    Yes, that's what I said before. What I want to know is if that method can be used in Metro apps build with js


    Luis Abreu

    Thursday, May 24, 2012 11:44 AM
  • Bumping this in regards to setPreviewMirror sti ll not working in RTM for JavaScript.

    Like OP, I am setting the src of a <video> tag to the MediaCapture object, and have preview ability. However, the setPreviewMirror function does not mirror the preview. In order to achieve the desired effect, I have set the msHorizontalMirror = true, but this only solves the tip of the problem. I am using the <video> tag as a preview for users to take webcam photos. I want the photos that the users take via my app to be an accurate representation of what they saw in the preview. However, setting msHorizontalMirror to true does not make the MediaCapture object capture photos in their mirrored form. Nor does calling setPreviewMirror(true) make the photos from the MediaCapture object mirrored.

    Wednesday, September 19, 2012 9:45 PM