Skip to content

Commit 291a9c1

Browse files
[UXP-104] fix plugin verison, fix responsiveness
1 parent 1afd5e1 commit 291a9c1

5 files changed

Lines changed: 114 additions & 26 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
"video.js": "^7.21.4",
161161
"videojs-contrib-quality-levels": "^2.0.9",
162162
"videojs-hls-quality-selector": "^1.1.1",
163-
"videojs-wavesurfer": "^3.9.0",
163+
"videojs-wavesurfer": "^3.10.0",
164164
"webfontloader": "1.6.28",
165165
"zone.js": "~0.11.5"
166166
},

src/app/shared/media-player/media-player.component.scss

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,37 @@
22
@import 'videojs-wavesurfer/dist/css/videojs.wavesurfer.css';
33

44
.media-container {
5-
max-height: 480px;
65
margin-bottom: 140px;
76
}
87

8+
99
.media-wrapper {
1010
background-color: black;
1111
position: relative;
1212
}
13+
14+
.playlist-wrapper {
15+
flex-basis: 20%;
16+
}
17+
18+
.overlay-onchange {
19+
position: absolute;
20+
top: 0;
21+
right: 0;
22+
left: 0;
23+
bottom: 0;
24+
z-index: 9;
25+
display: flex;
26+
align-items: center;
27+
justify-content: center;
28+
}
29+
30+
@include media-breakpoint-down(md) {
31+
.media-container {
32+
flex-direction: column;
33+
}
34+
35+
.playlist-wrapper {
36+
padding-top: 1rem;
37+
}
38+
}

src/app/shared/media-player/media-player.component.ts

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { Component, Inject, Input, OnDestroy, OnInit, PLATFORM_ID, ViewEncapsulation } from '@angular/core';
1+
import {
2+
Component,
3+
HostListener,
4+
Inject,
5+
Input,
6+
OnDestroy,
7+
OnInit,
8+
PLATFORM_ID,
9+
ViewChild,
10+
ViewEncapsulation
11+
} from '@angular/core';
212
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
313

414
import { BehaviorSubject, Observable } from 'rxjs';
@@ -24,6 +34,17 @@ export class MediaPlayerComponent implements OnInit, OnDestroy {
2434
*/
2535
@Input() startUUID: string;
2636

37+
/**
38+
* A reference to the video player container
39+
*/
40+
@ViewChild('videoContainerRef', {static: false}) videoContainerRef;
41+
42+
/**
43+
* A reference to the video playlist container
44+
*/
45+
@ViewChild('playlistContainerRef', {static: false}) playlistContainerRef;
46+
47+
2748
/**
2849
* A boolean representing whether audio player is initialized or not
2950
*/
@@ -103,15 +124,15 @@ export class MediaPlayerComponent implements OnInit, OnDestroy {
103124
this.isVideo$.next(this.mediaIsVideo(item));
104125
if (this.isVideo$.value) {
105126
if (this.isVideoPlayerInitialized$.value) {
106-
this.changePlayingItem(item);
127+
this.changePlayingItem();
107128
} else {
108-
this.initPlayer(item);
129+
this.initPlayer();
109130
}
110131
} else {
111132
if (this.isAudioPlayerInitialized$.value) {
112-
this.changePlayingItem(item);
133+
this.changePlayingItem();
113134
} else {
114-
this.initPlayer(item);
135+
this.initPlayer();
115136
}
116137
}
117138
}
@@ -125,13 +146,20 @@ export class MediaPlayerComponent implements OnInit, OnDestroy {
125146
}
126147
}
127148

149+
/**
150+
* Listen to window resize to adapt playlist size based on video size
151+
*/
152+
@HostListener('window:resize')
153+
onResize(): void {
154+
this.resizeMediaPlaylist();
155+
}
156+
128157
/**
129158
* Init videojs player with the given item as source
130159
*
131-
* @param item
132160
* @private
133161
*/
134-
private initPlayer(item: MediaViewerItem): void {
162+
private initPlayer(): void {
135163
if (this.isVideo$.value) {
136164
this.isVideoPlayerInitialized$.next(true);
137165
// stop audio player when switching from audio to video
@@ -141,6 +169,8 @@ export class MediaPlayerComponent implements OnInit, OnDestroy {
141169
this._document.getElementById('video_player'),
142170
this.currentItem$?.value
143171
);
172+
this.resizeMediaPlaylist();
173+
this.resizeMediaPlayer();
144174
}, 100);
145175

146176
} else {
@@ -152,6 +182,7 @@ export class MediaPlayerComponent implements OnInit, OnDestroy {
152182
this._document.getElementById('audio_player'),
153183
this.currentItem$?.value
154184
);
185+
this.resizeMediaPlaylist();
155186
}, 100);
156187

157188
}
@@ -165,10 +196,9 @@ export class MediaPlayerComponent implements OnInit, OnDestroy {
165196
/**
166197
* Change the source according to the given item
167198
*
168-
* @param item
169199
* @private
170200
*/
171-
private changePlayingItem(item: MediaViewerItem) {
201+
private changePlayingItem() {
172202
if (this.isVideo$.value) {
173203
// stop audio player when switching from audio to video
174204
this.disposeAudioPlayer();
@@ -233,4 +263,25 @@ export class MediaPlayerComponent implements OnInit, OnDestroy {
233263
this.isVideoPlayerInitialized$.next(false);
234264
}
235265
}
266+
267+
/**
268+
* Resize playlist container
269+
*/
270+
private resizeMediaPlaylist(): void {
271+
this.playlistContainerRef.nativeElement.style.height = `${this.videoContainerRef.nativeElement.getBoundingClientRect().height}px`;
272+
}
273+
274+
/**
275+
* Resize the video container
276+
*/
277+
private resizeMediaPlayer(): void {
278+
const aspectRatio = parseInt(this.currentItem$?.value.bitstream.firstMetadataValue('bitstream.video.width'), 10) /
279+
parseInt(this.currentItem$?.value.bitstream.firstMetadataValue('bitstream.video.height'), 10);
280+
281+
if (aspectRatio < 1) {
282+
const playerWidth = `${this.videoContainerRef.nativeElement.getBoundingClientRect().width * aspectRatio}px`;
283+
this.videoContainerRef.nativeElement.style.setProperty('width', playerWidth, 'important');
284+
this.videoContainerRef.nativeElement.parentElement.style.setProperty('width', playerWidth, 'important');
285+
}
286+
}
236287
}

src/app/shared/media-player/services/browser-videojs.service.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ export class BrowserVideojsService implements VideojsService {
1818
controls: true,
1919
bigPlayButton: false,
2020
autoplay: false,
21-
fluid: false,
21+
responsive: true,
22+
fluid: true,
2223
loop: false,
23-
with: 600,
24-
height: 480,
2524
plugins: {
2625
wavesurfer: {
2726
backend: 'MediaElement',
@@ -43,10 +42,10 @@ export class BrowserVideojsService implements VideojsService {
4342
controls: true,
4443
bigPlayButton: true,
4544
autoplay: false,
46-
fluid: false,
4745
loop: false,
48-
with: 600,
49-
height: 480
46+
responsive: true,
47+
fluid: true,
48+
aspectRatio: undefined
5049
};
5150

5251
/**
@@ -68,11 +67,23 @@ export class BrowserVideojsService implements VideojsService {
6867
* Return an instance of videojs player for video media
6968
*/
7069
initVideoPlayer(element: HTMLElement, mediaItem: MediaViewerItem): any {
70+
const currentVideoRatio = parseInt(mediaItem.bitstream.firstMetadataValue('bitstream.video.width'), 10) /
71+
parseInt(mediaItem.bitstream.firstMetadataValue('bitstream.video.height'), 10);
72+
73+
if (currentVideoRatio < 1) {
74+
// videojs available ratios are '16:9', '9:16', '4:3', we set it only for portrait mode since the width would be off for those
75+
this.configVideo = {
76+
...this.configVideo,
77+
aspectRatio: '9:16'
78+
};
79+
}
80+
7181
const videoPlayer = videojs(element, this.configVideo, () => {
7282
videoPlayer.src({ src: mediaItem?.manifestUrl, type: 'application/dash+xml' });
7383
(videoPlayer as any).hlsQualitySelector();
7484
});
7585

7686
return videoPlayer;
7787
}
88+
7889
}

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13739,13 +13739,13 @@ videojs-vtt.js@^0.15.5:
1373913739
dependencies:
1374013740
global "^4.3.1"
1374113741

13742-
videojs-wavesurfer@^3.9.0:
13743-
version "3.9.0"
13744-
resolved "https://registry.yarnpkg.com/videojs-wavesurfer/-/videojs-wavesurfer-3.9.0.tgz#685b0874540167887b3df4c86b11fd617bc20c21"
13745-
integrity sha512-gAQUFLlAmNXW8hCQwlJRsMl98Q4LyPzd318yDmuzzWLlupBpV3b4riAguYIHLC0d3svt1pgX8Vz8cX91OaPgWQ==
13742+
videojs-wavesurfer@^3.10.0:
13743+
version "3.10.0"
13744+
resolved "https://registry.yarnpkg.com/videojs-wavesurfer/-/videojs-wavesurfer-3.10.0.tgz#4d19ef53b13903327918f413c15e882f780b57ee"
13745+
integrity sha512-NFLnPtlq3poxvPIAAHsIaT53SifF3Npu5q1F932/WLkTA/uuPKAohSUw2WjzDgJ/2/xtGnuCGE6CGQYYhoeatg==
1374613746
dependencies:
1374713747
video.js ">=7.0.5"
13748-
wavesurfer.js ">=6.3.0"
13748+
wavesurfer.js ">=6.3.0 <7.0.0"
1374913749

1375013750
virtual-dom@^2.1.1:
1375113751
version "2.1.1"
@@ -13812,10 +13812,10 @@ watchpack@^2.4.0:
1381213812
glob-to-regexp "^0.4.1"
1381313813
graceful-fs "^4.1.2"
1381413814

13815-
wavesurfer.js@>=6.3.0:
13816-
version "7.4.6"
13817-
resolved "https://registry.yarnpkg.com/wavesurfer.js/-/wavesurfer.js-7.4.6.tgz#5fd381c773d2e184b2def732fabe41aa3ce767e5"
13818-
integrity sha512-uQDw132ucreP6rqJKou9vWe59QPZQ4PGftQml58JbwMzna4pJjUxXDZv+ubV7LJBkX1kaO/9BEmBRpmR64O3rQ==
13815+
"wavesurfer.js@>=6.3.0 <7.0.0":
13816+
version "6.6.4"
13817+
resolved "https://registry.yarnpkg.com/wavesurfer.js/-/wavesurfer.js-6.6.4.tgz#45e2d613fbfd60d906362ed6e11b649f481e4485"
13818+
integrity sha512-nBbc0pD/3FdClxKUKL1UW2V9AJPL+JOjC8T6/YF9/FCAn4uo+H6Y8VBkXo9UJXIHoBewoc7iXj3tPeL0UCJhjA==
1381913819

1382013820
wbuf@^1.1.0, wbuf@^1.7.3:
1382113821
version "1.7.3"

0 commit comments

Comments
 (0)