augmentmy-world / arStudio

A innovative Web editor for Augmented Reality
https://webarstudio.tripod-digital.co.nz
MIT License
54 stars 34 forks source link

Solve StopAR issue with video #6

Closed kalwalt closed 4 years ago

kalwalt commented 4 years ago

This PR solve the issue https://github.com/augmentmy-world/arStudio/issues/5. The video was already deleted by this.arController.dispose(); see the code: https://github.com/augmentmy-world/arStudio/blob/08583457e9969023168b86d0eefd24f37a151659/editor/js/components/arcontroller.component.js#L304-L312 For this reason getTracks() find the video src as null and fails. My code solution move the dispose() after the getTracks() call and perform a iteration to stop eventually other videos stream. My solution:

ArControllerComponent.prototype.stopAR = function(){
    console.log("Stop AR");
    this.running = false;
    if(this._video !== undefined){
      console.log(this._video);
      var videoElem = this._video;
      var stream = videoElem.srcObject;
      var tracks = stream.getVideoTracks();
      tracks.forEach(function(track) {
        track.stop();
      });

      videoElem.srcObject = null;
      videoElem.src = null;
      videoElem.remove();
      if(this.arController)
          this.arController.dispose();
    }

I used getVideoTracks() instead of getTracks() , i am not sure which one is better ro use.

ThorstenBux commented 4 years ago

Awesome thanks. Will merge that straight away 🥇