videogular / ngx-videogular

The HTML5 video player for Angular 2 and successor to videogular2
MIT License
133 stars 36 forks source link

Autoplay not working #105

Open LucaDaniele99 opened 2 years ago

LucaDaniele99 commented 2 years ago

Description

I'm having some trouble autoplaying the video when loading the page. The video source URL is loaded dinamically so I've wrapped vg-player with a div and a ngIf so it shows only when the source URL is not empty. If I add the autoplay="true" to the video tag when I recompile the first time it works but on every reload of the page after it doesn't work anymore. The video loads correctly but I have to press the play button manually.

I've also tried to implement APIs using the onPlayerReady event but then the subscribe is not fired.

ngx-videogular version: 6.0.0

Schermata 2022-07-22 alle 12 24 04 Schermata 2022-07-22 alle 12 24 15 Schermata 2022-07-22 alle 12 15 45

Expected Behavior

Expected Behavior: video autoplay when player is loaded

Actual Behavior

Actual Behavior: I have to press play manually, autoplay works only on recompile. APIs not firing

LucaDaniele99 commented 2 years ago

I've also tried this piece of code

Schermata 2022-07-24 alle 15 54 25

The subscribe fires but this.VGapi.play(); doesn't work and neither this.VGapi.getDefaultMedia().play() does

barrct commented 1 year ago

This is still an issue in 7.0.1, it just doesn't work and no errors to track anything down.

image

image

Bazhan4ik commented 1 year ago

I have the same issue

AncaStefaniaa commented 1 year ago

I also have the same issue please fix this

Haremun commented 6 months ago

It appears the issue lies not with Videogular, but rather with Angular itself. Here's the solution that resolved the problem for me:

<video
        #media
        (onGetBitrates)="bitrates = $event"
        [vgMedia]="$any(media)"
        [vgHls]="currentStream.source"
        crossorigin
        (canplay)="media.play()"
        (loadedmetadata)="media.muted = true">
</video>

https://stackoverflow.com/a/53767478