How to save video recording video in application with window 8?

This is the code to capture video and save video. But it does not save video content. It gives an error message

JavaScript runtime error: type mismatch

It is part of the saveVideofunction method copyAsync.

function captureVideo() {      
        var cam = Windows.Media.Capture.CameraCaptureUI();
        cam.videoSettings.allowTrimming = true;
        cam.videoSettings.format = Windows.Media.Capture.CameraCaptureUIVideoFormat.mp4;
        cam.videoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxVideoResolution.standardDefinition;
               cam.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.video).then(function (file) {
            if (file) {
                photoBlobUrl = URL.createObjectURL(file, { oneTimeOnly: true });
                var myVideo = document.getElementById("videoId");                  
                myVideo.src = photoBlobUrl;
                myVideo.play();
            }
            else {
            }
        });
    }
function saveVideo() {
        var output;
        var input;
        var outputStream;           
        var picturesLib = Windows.Storage.KnownFolders.picturesLibrary;

         picturesLib.createFileAsync("v1.mp4",
                                        Windows.Storage.CreationCollisionOption.replaceExisting).
                                    then(function(file) {
                                        return file.openAsync(Windows.Storage.FileAccessMode.readWrite);
                                    }).then(function (stream) {

                                        outputStream = stream;
                                        output = stream.getOutputStreamAt(0);
                                        input = photoBlobUrl;
                                        return Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output);
                                    }).then(function() {
                                        return output.flushAsync();
                                    }).done(function() {
                                        input.close();
                                        output.close();
                                        outputStream.close();

                                    });

    }
+4
source share
1 answer

A StorageFileusually represents a file that is already saved. If you look StorageFile.Pathafter shooting, it should be something like this:

C:\Users\[username]\AppData\Local\Packages\[appname]\TempState\picture003.jpg

Since the file is already saved, you can move or copy it to another location, for example:

storageFile.moveAsync(Windows.Storage.KnownFolders.picturesLibrary)

Hope this helps.

+1
source

All Articles