mediaElement 适用于 Chrome 但不适用于 Firefox 或 Edge(网络音频 api / angularJS)
mediaElement works on Chrome but not Firefox or Edge (web audio api / angularJS)
我在这里找不到我的错误。我将 soundcloud 音轨连接到 audioNode
并将其连接到 biquadFilter
,这样我就可以对其应用均衡。所有这些都在 AngularJs App
中
它在 chrome 中运行没有任何问题,但在 Firefox 和 MS Edge 中我收到此错误:
Error: this.source.mediaElement is undefined
soundcloudObject.prototype.playPause@http://localhost:8080/app/app.module.js:535:13
这是代码的相关部分
app.factory("soundcloudObject", function(){
function soundcloudObject(url){
if (typeof url === 'undefined') {
url= "http://api.soundcloud.com/tracks/119451720/stream";
}
var clientId = "?client_id=MY_CLIENT_ID";
var song = new Audio();
song.crossOrigin = "anonymous";
song.src = url + clientId;
this.source = scope.audioContext.createMediaElementSource(song);
}
var isPlaying = false;
soundcloudObject.prototype.playPause = function(){
if (isPlaying === true){
this.source.disconnect();
isPlaying = false;
console.log("Music Is Not Playing");
}
else{
this.source.connect(scope.musicEq);
this.source.mediaElement.play(); //##################//**LINE 535**//
isPlaying = true;
}
};
soundcloudObject.prototype.play = function(){
this.source.disconnect();
this.source.connect(scope.musicEq ); // connect to EQ Node
this.source.mediaElement.play();
isPlaying = true;
};
soundcloudObject.prototype.disconnect = function(){
this.source.disconnect();
};
return soundcloudObject;
});
我用控制器中的所有数据创建了一个 soundcloudObject,然后在我的视图中将其调用到 .play()
或 .playPause()
。
对象(称为 soundcloud)存在,正如我在日志中看到的那样:
scope.soundcloud
Object { source: MediaElementAudioSourceNode }
但后来我调用 soundcloud.play()
得到 TypeError: this.source.mediaElement is undefined
我一窍不通...
看起来 .mediaElement
已弃用。
修复是在节点链中返回并使用歌曲(媒体元素源本身)song.play()
,它在 firefox、chrome 和 edge 中有效。
我在这里找不到我的错误。我将 soundcloud 音轨连接到 audioNode
并将其连接到 biquadFilter
,这样我就可以对其应用均衡。所有这些都在 AngularJs App
它在 chrome 中运行没有任何问题,但在 Firefox 和 MS Edge 中我收到此错误:
Error: this.source.mediaElement is undefined
soundcloudObject.prototype.playPause@http://localhost:8080/app/app.module.js:535:13
这是代码的相关部分
app.factory("soundcloudObject", function(){
function soundcloudObject(url){
if (typeof url === 'undefined') {
url= "http://api.soundcloud.com/tracks/119451720/stream";
}
var clientId = "?client_id=MY_CLIENT_ID";
var song = new Audio();
song.crossOrigin = "anonymous";
song.src = url + clientId;
this.source = scope.audioContext.createMediaElementSource(song);
}
var isPlaying = false;
soundcloudObject.prototype.playPause = function(){
if (isPlaying === true){
this.source.disconnect();
isPlaying = false;
console.log("Music Is Not Playing");
}
else{
this.source.connect(scope.musicEq);
this.source.mediaElement.play(); //##################//**LINE 535**//
isPlaying = true;
}
};
soundcloudObject.prototype.play = function(){
this.source.disconnect();
this.source.connect(scope.musicEq ); // connect to EQ Node
this.source.mediaElement.play();
isPlaying = true;
};
soundcloudObject.prototype.disconnect = function(){
this.source.disconnect();
};
return soundcloudObject;
});
我用控制器中的所有数据创建了一个 soundcloudObject,然后在我的视图中将其调用到 .play()
或 .playPause()
。
对象(称为 soundcloud)存在,正如我在日志中看到的那样:
scope.soundcloud
Object { source: MediaElementAudioSourceNode }
但后来我调用 soundcloud.play()
得到 TypeError: this.source.mediaElement is undefined
我一窍不通...
看起来 .mediaElement
已弃用。
修复是在节点链中返回并使用歌曲(媒体元素源本身)song.play()
,它在 firefox、chrome 和 edge 中有效。