Javascript 音频和视频HTML5元素中的音频在使用WebAudio API时被静音

Javascript 音频和视频HTML5元素中的音频在使用WebAudio API时被静音,javascript,web-audio-api,Javascript,Web Audio Api,我正在尝试从视频中获取音频,以使用Web音频API。但视频中的音频是静音的。当我在本地测试此代码时,HTML5音频工作(在JSFIDLE上,当Web audio API打开时,HTML5音频不工作),但在本地和JSFIDLE上,视频没有音频(它是静音的,用户无法更改)。控制台中不显示任何错误。我添加了应用于自动播放策略更改的函数:。这是我的密码: //谷歌新政策要求更多信息:https://developers.google.com/web/updates/2017/09/autoplay-p

我正在尝试从视频中获取音频,以使用Web音频API。但视频中的音频是静音的。当我在本地测试此代码时,HTML5音频工作(在JSFIDLE上,当Web audio API打开时,HTML5音频不工作),但在本地和JSFIDLE上,视频没有音频(它是静音的,用户无法更改)。控制台中不显示任何错误。我添加了应用于自动播放策略更改的函数:。这是我的密码:

//谷歌新政策要求更多信息:https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio
var-context=null;
var myAudio,source,splitter,listener=null;
var FrontLeft、FrontCenter、FrontRight、SurroundLeft、SurroundRight、Sub=null;
var PannerNodeObject=[FrontLeft,FrontCenter,FrontRight,SurroundLeft,SurroundRight,Sub];
var distanceFromScreen,screenCenterY=null;
变量x_FrontLeft,y_FrontLeft,z_FrontLeft=null;
变量x_FrontCenter,y_FrontCenter,z_FrontCenter=null;
变量x_FrontRight,y_FrontRight,z_FrontRight=null;
变量x_SurroundLeft,y_SurroundLeft,z_SurroundLeft=null;
var x_SurroundRight,y_SurroundRight,z_SurroundRight=null;
var x_Sub,y_Sub,z_Sub=null;
var web\u Audio\u enable=false;
var initailPosition=[[x_FrontLeft,y_FrontLeft,z_FrontLeft],
[x_FrontCenter,y_FrontCenter,z_FrontCenter],
[x_FrontRight,y_FrontRight,z_FrontRight],
[x_-SurroundLeft,y_-SurroundLeft,z_-SurroundLeft],
[x_-SurroundRight,y_-SurroundRight,z_-SurroundRight],
[x_Sub,y_Sub,z_Sub];
//当用户与页面交互时恢复播放的一行代码。
函数startFunction(){
//创建拆分器
上下文=新的AudioContext();
//获取音频元素
myAudio=document.getElementById('video');
//myAudio=document.querySelector('video');
source=context.createMediaElementSource(myAudio);
//var dest=context.createMediaStreamDestination();
//分路器信道L、R、SL、SR、C、LFE
splitter=newchannelsplitternode(上下文,{numberOfOutputs:6});
//设channel_merge=newchannelmergernode(上下文,{numberOfInputs:2});
listener=context.listener;
源。连接(拆分器);
web\u Audio\u enable=真;
启动函数();
log(“播放已成功恢复”);
}
//估计声源放置的屏幕宽度
//注:这是估计,它不是很准确,但对于这个项目,它是准确的
//由“创建”摄影机使用
函数估计_ScreenParams(){
var$el=document.createElement('div');
$el.style.width='1cm';
$el.style.height='1cm';
$el.style.backgroundColor='#ff0000';
$el.style.position='fixed';
$el.style.bottom=0;
文件.正文.附件(el美元);
变量screenHeight=window.screen.height/$el.offsetHeight;
var screenWidth=window.screen.width/$el.offsetWidth;
console.log(“屏幕宽度(厘米):+屏幕宽度);
console.log(“屏幕高度(厘米):+屏幕高度);
var screenDiagonalInches=Math.sqrt(Math.pow((window.screen.width/$el.offsetWidth),2)+Math.pow((window.screen.height/$el.offsetHeight),2))/2.54;
console.log(“屏幕对角线输入:”+屏幕对角线);
文件.body.removeChild($el);
//屏幕中心高度(米)
变量screenCenterY=(屏幕高度/2)/100;
//根据估计的屏幕对角线长度和分辨率计算距离
//屏幕分辨率
var screenResWidth=window.screen.width*window.devicePixelRatio;
var screenResHeight=window.screen.height*window.devicePixelRatio;
var loc_distanceFromScreen=null;
//distanceFromScreen将用于左右环绕扬声器的初始定位
//距离以米为单位
如果(屏幕对角化<14){
loc_distanceFromScreen=0.61;//最小距离
}
否则{
loc_距离屏幕=0.61+(数学四舍五入(屏幕对角化-14)/2)*0.15;
}
控制台日志(“与屏幕的估计距离:”+loc_distanceFromScreen);
distanceFromScreen=loc\u distanceFromScreen;
返回屏幕中心;
}
函数集\u pannerNode(节点,panningModel/*'HRTF'*/,距离模型/*可能的值为“线性”、“反向”和“指数”。默认值为“反向”。*/,参考距离,最大距离,滚动因子,圆锥内角,圆锥外角,圆锥外增益,x,y,z/*位置*/,n/*PannerNodeObject的索引*/){
node=context.createPanner();
//设置选项
node.panningModel=panningModel;
node.distanceModel=距离模型;
node.refDistance=refDistance;
node.maxDistance=maxDistance;
node.rolloffFactor=rolloffFactor;
node.coneInnerAngle=coneInnerAngle;
node.coneoutrangle=coneoutrangle;
node.coneOuterGain=coneOuterGain;
//设置位置
if(节点位置X){
node.positionX.setValueAtTime(x,context.currentTime);
node.positionY.setValueAtTime(y,context.currentTime);
node.positionZ.setValueAtTime(z,context.currentTime);
}否则{
节点设置位置(x,y,z);
}
PannerNodesObject[n]=节点;
}
//旋转函数
//cx、cy、cz-全球旋转中心
变量温度位置=[-0.12,0.835,0],/*左前*/
[0.12,0.835,0],/*右前*/
[0.0,0.85,0],/*前中心*/
[0.08,0.84,0],/*Sub*/
[-0.17,-0.83,0],/*环绕左侧*/
[0.17, -0.83, 0]]; /* 右转*/
函数集_旋转(x,y,angle,n/*n是一个int,表示要更改的初始位置是扬声器的索引0-FL,1-FC,2-FR等。*/){
/* 
目前未使用
*/
初始位置[n][0]=临时位置[n][0];
初始位置[n][1]=临时位置[n][1];
初始位置[n][2]=临时位置[n][2];
console.log(n+“x:”+initailPositi