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

video not auto playing when refresh page #916

Open
mathiasVoelcker opened this issue Mar 15, 2021 · 0 comments
Open

video not auto playing when refresh page #916

mathiasVoelcker opened this issue Mar 15, 2021 · 0 comments

Comments

@mathiasVoelcker
Copy link

mathiasVoelcker commented Mar 15, 2021

Description

I have a webpage with a videogular component, and I want the video to play automatically once the user enters the page. If I navigate to the page through an url, the video play fine, but if I reload the page, the video don't play.

Expected Behavior

Video play automatically when I reload the page

Actual Behavior

Video doesn't play automatically when I reload the page

Steps to Reproduce

here is my code:

<vg-player (onPlayerReady)="onPlayerReady($event)" [style.width.px]="width" [style.height.px]="height">
    <vg-overlay-play></vg-overlay-play>
    
    <vg-controls vgFor="singleVideo">
        <vg-play-pause></vg-play-pause>
        <vg-mute></vg-mute>
        <vg-volume></vg-volume>
        <vg-fullscreen></vg-fullscreen>
    </vg-controls>

    <video #media
        [vgMedia]="media"
        src="{{videoUrl}}"
        id="singleVideo"
        type="video/mp4"
        preload="auto"
        autoplay="true"
        crossorigin
        >
    </video>
</vg-player>

import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { VgAPI } from 'videogular2/compiled/core';

@Component({
  selector: 'video-player',
  templateUrl: './video-player.component.html',
  styleUrls: ['./video-player.component.css']
})
export class VideoPlayerComponent  {

  @Input() 
  set src(src: string)
  {
    this.videoUrl = src;
    if (this.api != null)
    {
      this.playVideo();
    }
  }
  @Input() height: number;
  @Input() width: number;
  @Output() onFinish = new EventEmitter<any>();

  videoUrl: string;
  isPlaying: boolean;

  constructor() { }

  api: VgAPI

  onPlayerReady(api: VgAPI) {
    this.api = api;
    this.playVideo();

    this.api.getDefaultMedia().subscriptions.ended.subscribe(
      () => {
        this.api.getDefaultMedia().currentTime = 0;
        this.finishVideo();
      }
    );
  }

  playVideo() {
    this.api.currentTime = 0;
    this.api.play();
  }

  finishVideo() {
    this.onFinish.emit();
  }

}

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

1 participant