# Issues with Video Tag in Ionic

**URL:** <https://forum.ionicframework.com/t/issues-with-video-tag-in-ionic/126647>\
**Category:** ionic-v3\
**Created:** [April 2, 2018, 6:09pm UTC](https://forum.ionicframework.com/t/issues-with-video-tag-in-ionic/126647 "2018-04-02T18:09:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![greggarson](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@greggarson](https://forum.ionicframework.com/u/greggarson)\
**Post date:** [April 2, 2018, 6:09pm UTC](https://forum.ionicframework.com/t/issues-with-video-tag-in-ionic/126647/1 "2018-04-02T18:09:19Z")

</div>

I’m currently running into an issue with HTML5 Video tags in Ionic 3. When the app i’m building is running or built to an iPad the app will, after 17 page loads of a page containing a video tag, stop displaying the video referenced and just offer the play button with a line through it error. Watching the network tab in safari suggests that the video is continuing to be requested and received. The Video tag just fails to play the video.

A test project displaying the issue at hand can be found here: [https://github.com/greggarson/VideoTagTest](https://github.com/greggarson/VideoTagTest)

I’ve been able to reproduce this issue against both WKWebView and UIWebView. Has anyone seen something like this? Any pointers would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![greggarson](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@greggarson](https://forum.ionicframework.com/u/greggarson)\
**Post date:** [April 3, 2018, 12:07am UTC](https://forum.ionicframework.com/t/issues-with-video-tag-in-ionic/126647/2 "2018-04-03T00:07:02Z")

</div>

Managed figure this one out. It appears that the removal of the Page isn’t enough to unload the video from memory, which is probably what was causing the issue.

A snippet like:

```auto
ionViewWillLeave() { 
    if(this.videoPlayerElement) { 
        this.videoPlayerElement.nativeElement.pause(); 
        this.videoPlayerElement.nativeElement.src = ''; } 
    }
}

```

appears to solve the problem.

---

<div class="post-metadata">

**Author:** ![robinyo](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/robinyo/32/115964_2.png) [@robinyo](https://forum.ionicframework.com/u/robinyo)\
**Post date:** [April 3, 2018, 1:49am UTC](https://forum.ionicframework.com/t/issues-with-video-tag-in-ionic/126647/3 "2018-04-03T01:49:49Z")

</div>

@greggarson

I created a media component, so in the `ngAfterViewInit()` I do the following:

```auto
  ...

  @ViewChild('video')
  public video: ElementRef;

  private stream: any;

  ...

  public ngAfterViewInit() {

    const constraints = {
      audio: false,
      video: {
        width: { min: 1024, ideal: 1280, max: 1920 },
        height: { min: 776, ideal: 720, max: 1080 },
        facingMode: 'environment'
      }
    };

    if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {

      navigator.mediaDevices.getUserMedia(constraints).then(stream => {
        this.video.nativeElement.src = window.URL.createObjectURL(stream);
        this.stream = stream;
        this.video.nativeElement.play();
      }).catch(function(err) {
        this.logger.error(err.name + ': ' + err.message);
      });

    } else {
      this.logger.error('Your browser does not support the mediaDevices API');
    }
  }

```

**Note:** I don’t need audio and I want to use the rear facing camera.

In the `ngOnDestroy()` I do the following:

```auto
  public ngOnDestroy() {

    if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {

      if (this.stream) {
        this.video.nativeElement.pause();
        this.video.nativeElement.src = '';
        this.stream.getTracks().forEach( track => track.stop() );
      }
    }
  }

```

The Component’s template:

```auto
  selector: 'page-media',
  template: `
    <div id="media-container">
      <div id="media">
        <video #video id="video" muted playsinline autoplay></video>
      </div>
    </div>`

```

And, the Component’s .scss:

```auto
  page-media {

    #media-container {
      background-color: black;
      max-width: 1920px;
    }

    #media {
      width: 100%;
    }

    #video {
      width: 100%;
    }

  }

```

The Page’s markup:

```auto
  <ion-content no-bounce class="media-container">

    <ion-grid>
      <ion-row align-items-center>
        <page-media>
        </page-media>
      </ion-row>
    </ion-grid>

  </ion-content>

```

The Page’s .scss:

```auto
    .media-container {

      .scroll-content {
        background-color: black !important;
        display: flex;
        flex-direction: column;
        overflow: hidden;
      }

      ion-grid {
        padding: 0;
        height: 100%;
      }

      ion-row {
        flex: 1;
      }

    }

```

---

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [April 3, 2018, 2:16am UTC](https://forum.ionicframework.com/t/issues-with-video-tag-in-ionic/126647/4 "2018-04-03T02:16:34Z")

</div>

@robinyo Your posts here have always been good, but lately you’ve taken it to the next level. Really good stuff.

---

<div class="post-metadata">

**Author:** ![greggarson](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@greggarson](https://forum.ionicframework.com/u/greggarson)\
**Post date:** [April 3, 2018, 5:00pm UTC](https://forum.ionicframework.com/t/issues-with-video-tag-in-ionic/126647/5 "2018-04-03T17:00:54Z")

</div>

@robinyo Thanks for this, looks like the clean up you’re doing is basically the same as mine. I’m not using the mediaDevices API at all right now though, so i’ll take a look at that too to see if it’s any help.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:42pm UTC](https://forum.ionicframework.com/t/issues-with-video-tag-in-ionic/126647/6 "2021-07-19T21:42:25Z")

</div>

Closed on July 19, 2021, 9:42pm UTC


