diff options
Diffstat (limited to 'examples/browser-stream-to-audio.js')
-rw-r--r-- | examples/browser-stream-to-audio.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/examples/browser-stream-to-audio.js b/examples/browser-stream-to-audio.js new file mode 100644 index 0000000..84dfdfd --- /dev/null +++ b/examples/browser-stream-to-audio.js @@ -0,0 +1,19 @@ +var WebTorrent = require('webtorrent')
+
+var client = new WebTorrent()
+
+client.add(magnet_uri, function (torrent) {
+ // Got torrent metadata!
+ console.log('Torrent info hash:', torrent.infoHash)
+
+ // Let's say the first file is an mp3 audio file
+ var file = torrent.files[0]
+
+ // Create an audio element
+ var audio = document.createElement('audio')
+ audio.controls = true
+ document.body.appendChild(audio)
+
+ // Stream the audio into the audio tag
+ file.createReadStream().pipe(audio)
+})
|