2016-04-21 82 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中起作用。

相關問題