如何在window 8 metro app中保存捕获视频文件?

时间:2014-09-09 07:33:07

标签: javascript windows windows-runtime windows-store-apps html5-video

这些是捕获视频和保存视频的代码。但它不保存视频内容。它给出了错误消息

  

JavaScript运行时错误:类型不匹配

它来自saveVideo函数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();

                                    });

    }

1 个答案:

答案 0 :(得分:1)

StorageFile通常表示已保存的文件。如果你在拍照后看StorageFile.Path,它应该是这样的:

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

由于文件已保存,您可以将其移动或复制到其他位置,如下所示:

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

我希望这会有所帮助。