Javascript 如何在Windows8 metro应用程序中保存捕获视频文件?
这些是用于捕获视频和保存视频的代码。但它不会保存视频内容。它给出了错误消息 JavaScript运行时错误:类型不匹配 它采用Javascript 如何在Windows8 metro应用程序中保存捕获视频文件?,javascript,windows,windows-runtime,windows-store-apps,html5-video,Javascript,Windows,Windows Runtime,Windows Store Apps,Html5 Video,这些是用于捕获视频和保存视频的代码。但它不会保存视频内容。它给出了错误消息 JavaScript运行时错误:类型不匹配 它采用saveVideo函数copyanc方法 function captureVideo() { var cam = Windows.Media.Capture.CameraCaptureUI(); cam.videoSettings.allowTrimming = true; cam.videoSettings.f
saveVideo
函数copyanc
方法
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();
});
}
StorageFile
通常表示已保存的文件。如果在拍摄照片后查看StorageFile.Path
,应该是这样的:
C:\Users\[username]\AppData\Local\Packages\[appname]\TempState\picture003.jpg
storageFile.moveAsync(Windows.Storage.KnownFolders.picturesLibrary)
由于文件已保存,您可以将其移动或复制到其他位置,如下所示:
C:\Users\[username]\AppData\Local\Packages\[appname]\TempState\picture003.jpg
storageFile.moveAsync(Windows.Storage.KnownFolders.picturesLibrary)
我希望这有帮助。不,我的意思是保存视频。我想保存视频内容图片库。在我的代码中,视频文件是创建的,但它是空的,并且出现错误。照片保存成功。我做到了。使用CameraCaptureUI.CaptureFileAsync创建输出文件。如果您得到一个零长度文件或其他错误,您应该首先解决这些问题。无需保存该文件,因为它已保存。您只需将其移动或复制到输出位置。