【问题标题】:Cordova video capture - how to get blob data?Cordova 视频捕获 - 如何获取 blob 数据?
【发布时间】:2018-01-23 19:13:41
【问题描述】:

我正在使用以下代码成功捕获视频流:

        navigator.device.capture.captureVideo(

            //...after recorded vid
            function(mediaFiles) {
                var i, path, len;
                for (i = 0, len = mediaFiles.length; i < len; i += 1) {
                    path = mediaFiles[i].fullPath;
                    app.f7.alert(path);
                }
            },

            //...couldn't get camera
            function() { app.f7.alert('Sorry - your recording device could not be accessed', 'Error'); },

            //...config
            {limit:2}
        );

我不知道如何获取已保存视频的 blob 数据。我有本地保存文件的文件路径,但我需要将数据保存到远程服务器,所以我需要它的数据。

成功回调传递了一个封装捕获视频的MediaFile 对象,但the docs don't discuss 可以通过任何方式获取其原始数据。有谁知道这是怎么实现的?

【问题讨论】:

    标签: javascript cordova video blob capture


    【解决方案1】:

    因为 MediaFile 会为您提供有关文件本身的信息,例如

    name: The name of the file, without path information. (DOMString)
    fullPath: The full path of the file, including the name. (DOMString)
    type: The file's mime type (DOMString)
    lastModifiedDate: The date and time when the file was last modified. (Date)
    size: The size of the file, in bytes. (Number)
    

    MediaFileData 将授予对

    的访问权限
    codecs: The actual format of the audio and video content. (DOMString)
    bitrate: The average bitrate of the content. The value is zero for images. (Number)
    height: The height of the image or video in pixels. The value is zero for audio clips. (Number)
    width: The width of the image or video in pixels. The value is zero for audio clips. (Number)
    duration: The length of the video or sound clip in seconds. The value is zero for images. (Number)
    

    而不是视频的内容。如果您想阅读其内容,请使用 MediaFile.fullPath 加载它。

    要加载视频,请查看this post,这可能会让您走上正轨。

    【讨论】:

    • 谢谢。 “使用 MediaFile.fullPath 加载它”——这正是我要问的。我有完整路径,但我不知道如何将路径指向的文件内容读入 blob。
    • 谢谢。我将对此进行调查 - 尽管该问题没有可接受的答案,并且 cmets 建议 OP 从未解决该问题。
    • 不高兴 - 该问题中的代码似乎与我捕获的视频文件所在的代码不同。请查看新问题 - 谢谢:stackoverflow.com/questions/45716487/…
    • 评论过
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多