Skip to content

Commit fd7e0c2

Browse files
Merge pull request #232 from cloudinary/use-fetch-format-angular
feat: add useFetchFormat prop in angular sdk
2 parents 9d2201f + bcc4d2e commit fd7e0c2

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class CloudinaryVideoComponent implements OnInit, OnChanges, OnDestroy {
5858
@Input('plugins') plugins: Plugins;
5959
@Input('poster') poster: string;
6060
@Input('innerRef') innerRef: ElementRef;
61+
@Input('useFetchFormat') useFetchFormat: boolean;
6162

6263
// Event emitters
6364
@Output() play: EventEmitter<any> = new EventEmitter();
@@ -87,7 +88,8 @@ export class CloudinaryVideoComponent implements OnInit, OnChanges, OnDestroy {
8788
this.sources,
8889
this.plugins,
8990
this.getVideoAttributes(),
90-
this.cldPoster
91+
this.cldPoster,
92+
{ useFetchFormat: this.useFetchFormat }
9193
);
9294

9395
// check if video should be muted. We need to take care of this here since Angular has a bug with binding the muted

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

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

@@ -90,6 +90,51 @@ describe('CloudinaryVideoComponent render', () => {
9090
.toEqual( 'video/webm; codecs=avc1.4D401E, mp4a.40.2');
9191
}));
9292

93+
it('should render video with input sources when using useFetchFormat', fakeAsync(() => {
94+
component.cldVid = cloudinaryVideo;
95+
component.useFetchFormat = true;
96+
component.sources = [
97+
{
98+
type: 'mp4',
99+
codecs: ['vp8', 'vorbis'],
100+
transcode: videoCodec(auto())
101+
},
102+
{
103+
type: 'webm',
104+
codecs: ['avc1.4D401E', 'mp4a.40.2'],
105+
transcode: videoCodec(vp9())
106+
},
107+
{
108+
type: 'ogv',
109+
codecs: ['theora'],
110+
transcode: videoCodec(theora())
111+
}];
112+
113+
fixture.detectChanges();
114+
tick(0);
115+
const vidElement: HTMLVideoElement = fixture.nativeElement;
116+
const video = vidElement.querySelector('video');
117+
118+
expect(video.childElementCount).toBe(3);
119+
120+
// First source
121+
expect(video.children[0].attributes.getNamedItem('src').value)
122+
.toEqual( 'https://res.cloudinary.com/demo/video/upload/vc_auto/f_mp4/sample');
123+
expect(video.children[0].attributes.getNamedItem('type').value)
124+
.toEqual( 'video/mp4; codecs=vp8, vorbis');
125+
126+
// Second source
127+
expect(video.children[1].attributes.getNamedItem('src').value)
128+
.toEqual( 'https://res.cloudinary.com/demo/video/upload/vc_vp9/f_webm/sample');
129+
expect(video.children[1].attributes.getNamedItem('type').value)
130+
.toEqual( 'video/webm; codecs=avc1.4D401E, mp4a.40.2');
131+
132+
// Third source
133+
expect(video.children[2].attributes.getNamedItem('src').value)
134+
.toEqual( 'https://res.cloudinary.com/demo/video/upload/vc_theora/f_ogv/sample');
135+
expect(video.children[2].attributes.getNamedItem('type').value)
136+
.toEqual( 'video/ogg; codecs=theora');
137+
}));
93138

94139
it('should contain poster when "auto" is passed as cldPoster', fakeAsync(() => {
95140
component.cldVid = new CloudinaryVideo('sample', { cloudName: 'demo'}, { analytics: false });

0 commit comments

Comments
 (0)