2016-04-21 81 views
0

我在这里找不到我的错误。我将soundcloud音轨连接到audioNode,并将其连接到biquadFilter,这样我就可以对其应用均衡。所有这一切都内的AngularJs应用mediaElement适用于Chrome,但不适用于Firefox或Edge(网络音频api/angularJS)

它的工作原理没有任何镀铬麻烦,但在Firefox和MS边缘我得到这个错误:

Error: this.source.mediaElement is undefined 
    [email protected]://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 object

但后来我打电话soundcloud.play(),我得到TypeError: this.source.mediaElement is undefined

我无言以对......

回答

0

看起来像.mediaElement已弃用。

该修复程序返回到节点链中并使用歌曲(媒体元素源本身)song.play()并且它在firefox,chrome和edge中起作用。

相关问题