0

I'm using Web Audio API to do a simple streaming audio using this function: function MyAudio(url){ var song = new Audio(); song.crossOrigin = "anonymous"; song.src = url;

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

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

    return MyAudio;
});

(more context here)

But I can't figure out how to pause or stop it. I saw other questions here but they use noteOn/noteOff and that doesn't work in my case.

I have tried without success things like:

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

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

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

No luck.

Community
  • 1
  • 1
distante
  • 6,438
  • 6
  • 48
  • 90

1 Answers1

0

Have you tried:

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