@achingbrain/videostream 中文文档教程

发布于 7年前 浏览 25 项目主页 更新于 3年前

Videostream

将数据从类似文件的可搜索对象流式传输到

目前仅支持 mp4 文件。 目标是支持 大多数符合 ISO/IEC 14496-12 的文件。

版本 2 被完全重写并且更加健壮 比以前依赖 mp4box.js 的版本。 唯一的重大倒退 与以前的体系结构相比,碎片化的 mp4 文件不是 支持的。 如果这是一个问题,我可能会在某个时候再次添加支持。

对大多数其他格式的支持将需要大量工作。

Usage

Videostream 只是导出一个函数。 像这样使用它:

var exampleFile = {
    createReadStream: function (opts) {
        var start = opts.start;
        var end = opts.end;
        // Return a readable stream that provides the bytes
        // between offsets "start" and "end" inclusive
    }
}

var VideoStream = require('videostream');

var elem = document.createElement('video');
var videostream = VideoStream(exampleFile, elem);

elem.addEventListener('error', function () {
  // listen for errors on the video/audio element directly
  var errorCode = elem.error
  var detailedError = videostream.detailedError
  // videostream.detailedError will often have a more detailed error message
})

Errors

通过监听 标签上的 'error' 事件来处理错误。

一些(但不是全部)错误也会导致 videostream.detailedError 被设置为 具有更多信息错误消息的错误值。

License

麻省理工学院。 版权所有 (c) John Hiesey。

Videostream

Streams data from a file-like seekable object into a <video> or <audio> node (a HTMLMediaElement). Seeking the media element will request a different byte range from the incoming file-like object.

For now only mp4 files are supported. The goal is to support most files that conform to ISO/IEC 14496-12.

Version 2 is completely rewritten and substantially more robust than the previous version that relied on mp4box.js. The only major regression compared to the previous architecture is that fragmented mp4 files aren't supported. If this is a problem I may add support again at some point.

Support for most other formats will take significant work.

Usage

Videostream just exports a function. Use it like this:

var exampleFile = {
    createReadStream: function (opts) {
        var start = opts.start;
        var end = opts.end;
        // Return a readable stream that provides the bytes
        // between offsets "start" and "end" inclusive
    }
}

var VideoStream = require('videostream');

var elem = document.createElement('video');
var videostream = VideoStream(exampleFile, elem);

elem.addEventListener('error', function () {
  // listen for errors on the video/audio element directly
  var errorCode = elem.error
  var detailedError = videostream.detailedError
  // videostream.detailedError will often have a more detailed error message
})

Errors

Handle errors by listening to the 'error' event on the <video> or <audio> tag.

Some (but not all) errors will also cause videostream.detailedError to be set to an error value that has a more informative error message.

License

MIT. Copyright (c) John Hiesey.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文