首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Chrome分析网页中的所有音频

Chrome分析网页中的所有音频
EN

Stack Overflow用户
提问于 2015-01-14 08:21:49
回答 1查看 272关注 0票数 0

有人知道如何通过createAnalyser()中的分析器创建MediaElementSource或其他对象,用于发送网页上正在播放的所有声音数据吗?我希望能够在不知道声音的确切来源的情况下使用分析器。

编辑:我已经完成了我想要的,但不是通过捕获所有音频。下面的代码块让你在Google Play音乐播放器页面上获得一个分析器(只在我的库中测试,而不是在商店中测试)。

代码语言:javascript
复制
ctx = new (window.audioContext || window.webkitAudioContext);
source = iVisual.ctx.createMediaElementSource($('audio')[0]);
analyser = iVisual.ctx.createAnalyser();
EN

回答 1

Stack Overflow用户

发布于 2015-01-15 06:19:28

由于音频元素不应该同时播放,但如果您仍然希望对所有音频元素执行此操作,我将提供一些代码示例来执行此操作。下面是为您拥有的每个音频文件运行的for循环,它将使用适当的源为其创建一个音频元素,然后为该文件创建一个源节点(createMediaElementSource),并将该源节点连接到分析器。

代码语言:javascript
复制
onload = function () { //this will be executed when the page is ready
    window.audioFiles = ['audio1.mp3', 'audio2.mp3',...]; //the array with all audio files
    window.AudioContext = window.AudioContext || window.webkitAudioContext;
    context = new AudioContext();
    analyser = context.createAnalyser();
    analyser.connect(context.destination);

    //now we take all the files and create a button for every file

    sources = []; //we create an array where we store all the created sources in.
    for (var x in audioFiles) {
        var elem = document.createElement('audio'); //create an audio element
        elem.src = audioFiles[x]; //append the specific source to it.

        sources[x] = context.createMediaElementSource(elem); //create a mediasource for it
        sources[x].connect(analyser); //connect that to the analyser
    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27933923

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档