Is there anyway to render youtube audio from iframe using web audio api?

Is it possible to listen to the sound of a YouTube video that is in an iframe and then analyze it for use in a web audio api visualizer?

From how my site was created, I can get the source url from the iframe. Here is an example of one of my iframes:

<iframe id="youtube-player" type="text/html"  width="500" height="281" src="https://www.youtube.com/embed/JlhTiynRiXA?feature=oembed" frameborder="0" allowfullscreen></iframe>
+4
source share
1 answer

Hope this helps any future googlers.

The only way to do this is to use a streaming audio library (for example, youtube-audio-stream for Node) and buffer / stream the audio from the server side.

var express = require('express');
var router = express.Router();

var youtubeStream = require('youtube-audio-stream');

router.get('/stream/:videoId', function (req, res) {
    try {
        youtubeStream(req.params.videoId).pipe(res);
    } catch (exception) {
        res.status(500).send(exception)
    }
});

. AudioContext - , WebGL canvas (, pixi.js).

, :

function loadSound() {
  var request = new XMLHttpRequest();
  request.open("GET", "http://localhost:8000/stream/nl6OW07A5q4", true); 
  request.responseType = "arraybuffer"; 

  request.onload = function() {
      var Data = request.response;
      process(Data);
  };

  request.send();
}

function process(Data) {
  source = context.createBufferSource(); // Create Sound Source
  context.decodeAudioData(Data, function(buffer){
    source.buffer = buffer;
    source.connect(context.destination); 
    source.start(context.currentTime);
}) 

.

http://www.willvillanueva.com/the-web-audio-api-from-nodeexpress-to-your-browser/

: https://web.archive.org/web/20170715041035/http://www.willvillanueva.com/the-web-audio-api-from-nodeexpress-to-your-browser/

+4

Source: https://habr.com/ru/post/1568059/


All Articles