Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is not auto playing #11

Closed
neiromendez opened this issue Jul 15, 2020 · 9 comments
Closed

Is not auto playing #11

neiromendez opened this issue Jul 15, 2020 · 9 comments

Comments

@neiromendez
Copy link

neiromendez commented Jul 15, 2020

I implemented this component to my project in local works fine but in production is not working, the first load is no autoplay just appear the poster.

I'm listening this events without success:

    mounted() {
    document.addEventListener("error", this.vidError);
    document.addEventListener("ready", this.vidReady);
    document.addEventListener("loading", this.vidReady);
    document.addEventListener("ended", this.vidReady);
  }
  vidError(e: any): void {
    console.log(e);
    // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
    // @ts-ignore
    this.$refs.videobackground.player.play();
  }
  vidReady(e: any):void{
    console.log(e);
    // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
    // @ts-ignore
    this.$refs.videobackground.player.play();
  }

in the component too

<video-background
      ref="videobackground"
      :src="require('@/assets/vid.mp4')"
      :poster="image('logo.svg')"
      type="video/mp4"
      :style="
        $vuetify.breakpoint.xlOnly
          ? 'height: 100vh'
          : $vuetify.breakpoint.lgOnly
          ? 'height: 99vh'
          : $vuetify.breakpoint.mdOnly
          ? 'height: 80vh'
          : $vuetify.breakpoint.smAndDown
          ? 'height: 44vh'
          : ''
      "
      @error="vidError"
      @ready="vidReady"
    >

If anyone could help me to solve it, Thanks for the effort

@neiromendez neiromendez changed the title Is not auto play Is not auto playing Jul 15, 2020
@pmochine
Copy link
Contributor

@neiromendez First thing that I notice. Why do are using document event listeners? Like: document.addEventListener("error", this.vidError); You cannot listen to any since they are fired via the Vue component.

Second: You don't need to set the type="video/mp4". I won't change anything.

Another thing: Could you force to play the video like this.$refs.videobackground.player.play();?

My guess is that there is a problem for finding the source of the video. That's why it's not playing at all.

@neiromendez
Copy link
Author

@neiromendez First thing that I notice. Why do are using document event listeners? Like: document.addEventListener("error", this.vidError); You cannot listen to any since they are fired via the Vue component.

Second: You don't need to set the type="video/mp4". I won't change anything.

Another thing: Could you force to play the video like this.$refs.videobackground.player.play();?

My guess is that there is a problem for finding the source of the video. That's why it's not playing at all.

I @pmochine thanks for your reply, It is very strange because locally it works as expected. addEventListener from mounted. also, I put the this.$refs.videobackground.player.play(); but is not solving the problem

@pmochine
Copy link
Contributor

@neiromendez
My guess is that it cannot find the path of the video in production mode. You can easily check it via Chrome by inspecting the path of the video and check if you can manually play it.

@neiromendez
Copy link
Author

@neiromendez
My guess is that it cannot find the path of the video in production mode. You can easily check it via Chrome by inspecting the path of the video and check if you can manually play it.

https://mos-landing.firebaseapp.com/ you can take a look, sometimes the video start and others not

@pmochine
Copy link
Contributor

@neiromendez getting closer. Indeed sometimes the video starts, sometimes not. When it's not playing I get the error:

Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause(). https://goo.gl/LdLk22

Not sure where it is coming from.

@neiromendez
Copy link
Author

@neiromendez getting closer. Indeed sometimes the video starts, sometimes not. When it's not playing I get the error:

Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause(). https://goo.gl/LdLk22

Not sure where it is coming from.

yeap, I don't know why that's happening, I have been looking at the component but I can't find why that is happening

@pmochine
Copy link
Contributor

In the mean time you could use something like that:

<video-background
      ref="videobackground"
      :src="require('@/assets/vid.mp4')"
      :autoplay="false"
      ...
>

and then play the video after one second with

mounted(){
    window.setTimeout(() => this.$refs.videobackground.player.play(), 1000);
}

At least it should work with that.

@neiromendez
Copy link
Author

In the mean time you could use something like that:

<video-background
      ref="videobackground"
      :src="require('@/assets/vid.mp4')"
      :autoplay="false"
      ...
>

and then play the video after one second with

mounted(){
    window.setTimeout(() => this.$refs.videobackground.player.play(), 1000);
}

At least it should work with that.

In the mean time you could use something like that:

<video-background
      ref="videobackground"
      :src="require('@/assets/vid.mp4')"
      :autoplay="false"
      ...
>

and then play the video after one second with

mounted(){
    window.setTimeout(() => this.$refs.videobackground.player.play(), 1000);
}

At least it should work with that.

Unfortunately, it doesn't work.
But thx for your help

@pmochine
Copy link
Contributor

pmochine commented Jul 17, 2020

@neiromendez
I tried your version as a simple production page. But I cannot reproduce the error.

Here is one example: It works perfectly fine

<template>
  <div id="app">
    <video-background 
      ref="videobackground"
      src="https://mos-landing.firebaseapp.com/media/vid.da329944.mp4"
      style="max-height: 400px; height: 100vh;"
      @error="vidError"
      @ready="vidReady"
  >
      <h1 style="color: white;">Hello welcome!</h1>
  </video-background>
  </div>
</template>

<script>

 import VideoBackground from 'vue-responsive-video-background-player'
export default {
  name: 'App',
  components: {
    VideoBackground
  },
  mounted() {
   // Not sure why you have it here :D 
    document.addEventListener("error", this.vidError);
    document.addEventListener("ready", this.vidReady);
    document.addEventListener("loading", this.vidReady);
    document.addEventListener("ended", this.vidReady);
  },
  methods: {
    vidError() {
      console.log('vidError');
      this.$refs.videobackground.player.play();
    },
    vidReady(){
     console.log('vidReady');
      this.$refs.videobackground.player.play();
    }
  }  
}
</script>

Could you do me the favor and create the "simplest" version of the problem, so I can check it out.

@pmochine pmochine closed this as completed Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants