Skip to content

Commit a9065df

Browse files
feat: SNI-6952 add cldPoster to angular video component
1 parent ae5d41f commit a9065df

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

packages/angular/projects/cloudinary-library/src/lib/cloudinary-video.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Component, OnInit, Input, ElementRef, EventEmitter, Output, OnChanges, OnDestroy} from '@angular/core';
2-
import {CloudinaryVideo} from '@cloudinary/url-gen';
2+
import {CloudinaryImage, CloudinaryVideo} from '@cloudinary/url-gen';
3+
34
import {
45
cancelCurrentlyRunningPlugins,
56
HtmlVideoLayer,
@@ -13,6 +14,7 @@ import {
1314
* @type {Component}
1415
* @description The Cloudinary video component.
1516
* @prop {CloudinaryVideo} transformation Generated by @cloudinary/url-gen
17+
* @prop {CloudinaryImage | "auto"} transformation Generated by @cloudinary/url-gen
1618
* @prop {Plugins} plugins Advanced image component plugins lazyload()
1719
* @prop videoAttributes Optional attributes include controls, loop, muted, poster, preload, autoplay
1820
* @prop videoEvents Optional video events include play, loadstart, playing, error, ended
@@ -50,6 +52,7 @@ export class CloudinaryVideoComponent implements OnInit, OnChanges, OnDestroy {
5052
constructor(private el: ElementRef) { }
5153

5254
@Input('cldVid') cldVid: CloudinaryVideo;
55+
@Input('cldPoster') cldPoster: CloudinaryImage | 'auto';
5356
@Input('sources') sources: VideoSources;
5457
@Input('plugins') plugins: Plugins;
5558
@Input('poster') poster: string;
@@ -82,7 +85,8 @@ export class CloudinaryVideoComponent implements OnInit, OnChanges, OnDestroy {
8285
this.cldVid,
8386
this.sources,
8487
this.plugins,
85-
this.getVideoAttributes()
88+
this.getVideoAttributes(),
89+
this.cldPoster
8690
);
8791

8892
// check if video should be muted. We need to take care of this here since Angular has a bug with binding the muted
@@ -102,7 +106,7 @@ export class CloudinaryVideoComponent implements OnInit, OnChanges, OnDestroy {
102106
ngOnChanges() {
103107
if (this.htmlVideoLayerInstance) {
104108
cancelCurrentlyRunningPlugins(this.htmlVideoLayerInstance.htmlPluginState);
105-
this.htmlVideoLayerInstance.update(this.cldVid, this.sources, this.plugins, this.getVideoAttributes());
109+
this.htmlVideoLayerInstance.update(this.cldVid, this.sources, this.plugins, this.getVideoAttributes(), this.cldPoster);
106110
}
107111
}
108112

packages/angular/projects/cloudinary-library/src/tests/cloudinary-video.component.spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
22
import { CloudinaryVideoComponent } from '../lib/cloudinary-video.component';
3-
import {CloudinaryVideo} from '@cloudinary/url-gen';
3+
import {CloudinaryImage, CloudinaryVideo} from '@cloudinary/url-gen';
44
import { auto, vp9 } from '@cloudinary/url-gen/qualifiers/videoCodec';
55
import { videoCodec } from '@cloudinary/url-gen/actions/transcode';
66
import {ElementRef} from "@angular/core";
77

8+
const cloudinaryImage = new CloudinaryImage('sample', { cloudName: 'demo' }, { analytics: false });
89
const cloudinaryVideo = new CloudinaryVideo('sample', { cloudName: 'demo'}, { analytics: false });
910

1011
describe('CloudinaryVideoComponent render', () => {
@@ -90,6 +91,31 @@ describe('CloudinaryVideoComponent render', () => {
9091
.toEqual( 'video/webm; codecs=avc1.4D401E, mp4a.40.2');
9192
}));
9293

94+
95+
it('should contain poster when "auto" is passed as cldPoster', fakeAsync(() => {
96+
component.cldVid = cloudinaryVideo;
97+
component.cldPoster = "auto";
98+
const vidElement: HTMLVideoElement = fixture.nativeElement;
99+
const video = vidElement.querySelector('video');
100+
fixture.detectChanges();
101+
tick(0);
102+
103+
expect(video.attributes.getNamedItem('poster').value)
104+
.toEqual( 'https://res.cloudinary.com/demo/video/upload/q_auto/f_jpg/so_auto/sample');
105+
}));
106+
107+
it('should contain poster when cloudinary image is passed as cldPoster', fakeAsync(() => {
108+
component.cldVid = cloudinaryVideo;
109+
component.cldPoster = cloudinaryImage;
110+
const vidElement: HTMLVideoElement = fixture.nativeElement;
111+
const video = vidElement.querySelector('video');
112+
fixture.detectChanges();
113+
tick(0);
114+
115+
expect(video.attributes.getNamedItem('poster').value)
116+
.toEqual( 'https://res.cloudinary.com/demo/image/upload/sample');
117+
}));
118+
93119
it('should emit playing event', fakeAsync(() => {
94120
component.cldVid = cloudinaryVideo;
95121
fixture.detectChanges();

0 commit comments

Comments
 (0)