Skip to content

Commit 65edcb7

Browse files
committed
fix(VideoLoader): another fix for autoplay issue on ios safari with controls disabled
set the poster of the video component to placeholder on ngOnInit hook (before component renders)
1 parent fb3b03c commit 65edcb7

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ <h3>Bottom image imageLoaded event count: <span class="image-loaded-count">{{ im
3232
[loop]="true"
3333
[muted]="true"
3434
[autoplay]="true"
35-
[controls]="true"
35+
[controls]="false"
3636
[playsInline]="true"
3737
type="video/mp4"
3838
videoClass="video"

src/app/video-loader/video-loader/video-loader.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*ngIf="video"
33
[src]="src"
44
[class]="videoClass"
5-
[attr.poster]="poster"
5+
[poster]="poster"
66
[autoplay]="autoplay"
77
[loop]="loop"
88
[muted]="muted"

src/app/video-loader/video-loader/video-loader.component.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
NgZone,
66
ViewChild,
77
AfterViewInit,
8+
OnInit,
89
OnDestroy,
910
ChangeDetectorRef,
1011
ElementRef
@@ -46,7 +47,7 @@ import { ImageLoadedEvent } from '../../image-loader/shared/image-loaded-event.m
4647
templateUrl: './video-loader.component.html',
4748
styleUrls: ['./video-loader.component.scss']
4849
})
49-
export class VideoLoaderComponent implements AfterViewInit, OnDestroy {
50+
export class VideoLoaderComponent implements OnInit, AfterViewInit, OnDestroy {
5051
/**
5152
* Videos to select from
5253
*
@@ -205,6 +206,17 @@ export class VideoLoaderComponent implements AfterViewInit, OnDestroy {
205206
private ngZone: NgZone,
206207
private cdRef: ChangeDetectorRef
207208
) { }
209+
/**
210+
* Set poster before component renders to resolve an issue
211+
* with autoplay on safari browsers
212+
*
213+
* @memberof VideoLoaderComponent
214+
*/
215+
public ngOnInit(): void {
216+
if (this.video.poster && this.video.poster.placeholder) {
217+
this.poster = this.video.poster.placeholder;
218+
}
219+
}
208220
/**
209221
* Subscribe to `resize` window event observable
210222
* and run callback

0 commit comments

Comments
 (0)