From 04ec598159909e9bce1e08fc9c99b3cadb889d00 Mon Sep 17 00:00:00 2001 From: Josh Duff Date: Sat, 13 Dec 2014 21:51:35 -0600 Subject: [PATCH] Streaming video example Copied straight from #144 --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 4075c839..1a585b8a 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,30 @@ dragDrop('body', function (files) { }) ``` +##### Streaming to an HTML5 video element? Also simple! + +```js +var WebTorrent = require('webtorrent') + +var client = new WebTorrent() + +client.download(magnet_uri, function (torrent) { + // Got torrent metadata! + console.log('Torrent info hash:', torrent.infoHash) + + // Let's say the first file is a webm (vp8) or mp4 (h264) video... + var file = torrent.files[0] + + // Create a video element + var video = document.createElement('video') + video.controls = true + document.body.appendChild(video) + + // Stream the video into the video tag + file.createReadStream().pipe(video) +}) +``` + ##### Browserify WebTorrent works great with [browserify](http://browserify.org/), an npm module that let's