2016-04-17 5 views
0

Ich benutze Web Audio API, um ein einfaches Streaming Audio mit dieser Funktion: Funktion MyAudio (URL) { var song = new Audio(); song.crossOrigin = "anonym"; song.src = URL;So stoppen/pausieren Sie MediaElementSource (Web Audio API)

 this.source = context.createMediaElementSource(song); 
     this.source.connect(context.destination); 
    } 

    MyAudio.prototype.play = function(){ 
     this.source.mediaElement.play(); 
    }; 

    return MyAudio; 
}); 

(more context here)

Aber ich kann nicht herausfinden, wie es zu unterbrechen oder zu stoppen. Ich habe hier andere Fragen gesehen, aber sie benutzen noteOn/noteOff und das funktioniert in meinem Fall nicht.

Ich habe ohne Erfolg versucht, Dinge wie:

MyAudio.prototype.stop = function(){ 
    this.source.mediaElement.noteOff(); 
}; 

MyAudio.prototype.stop = function(){ 
    this.source.mediaElement.Stop(); 
}; 

MyAudio.prototype.stop = function(){ 
    this.source.stop(0); 
}; 

Kein Glück.

+0

Dies kann Ihnen helfen. http://stackoverflow.com/a/14697336/3279156 – sreeramu

Antwort

0

Haben Sie versucht:

MyAudio.prototype.stop = function(){ 
    this.source.mediaElement.pause(); 
    // To restart to the beginning on next play, not just resume 
    this.source.mediaElement.currentTime = 0; 
};