Skip to content

Commit

Permalink
Merge a68e9ba into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ibmdotcom-bot authored Dec 6, 2024
2 parents 51f418a + a68e9ba commit 3799b6d
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ $aspect-ratios: ((16, 9), (9, 16), (2, 1), (1, 2), (4, 3), (3, 4), (1, 1));
}
}

:host(#{$c4d-prefix}-video-player[background-mode='true']),
.#{$c4d-prefix}--video-player[background-mode='true'] {
:host(#{$c4d-prefix}-video-player[background-mode]),
.#{$c4d-prefix}--video-player[background-mode] {
.#{$c4d-prefix}--video-player__video-container {
padding: 0;
block-size: 100%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import '@carbon/ibmdotcom-web-components/es/components/background-media/index.js
<c4d-video-player-container
playing-mode="inline"
video-id="0_ibuqxqbe"
background-mode="true">
background-mode>
</c4d-video-player-container>
</c4d-background-media>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const WithVideo = (args) => {
opacity="${ifDefined(backgroundOpacity)}">
<c4d-video-player-container
video-id="0_ibuqxqbe"
background-mode="true"></c4d-video-player-container>
background-mode></c4d-video-player-container>
</c4d-background-media>
</div>
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ such:
<c4d-background-media slot="image" opacity="100">
<c4d-video-player-container
video-id="1_9h94wo6b"
background-mode="true"></c4d-video-player-container>
background-mode></c4d-video-player-container>
</c4d-background-media>
</c4d-leadspace>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const SuperWithVideo = (args) => {
<c4d-background-media slot="image" opacity="100">
<c4d-video-player-container
video-id="0_ibuqxqbe"
background-mode="true"></c4d-video-player-container>
background-mode></c4d-video-player-container>
</c4d-background-media>
</c4d-leadspace>
`;
Expand Down Expand Up @@ -335,7 +335,7 @@ export const TallWithVideo = (args) => {
<c4d-background-media slot="image" opacity="100">
<c4d-video-player-container
video-id="0_ibuqxqbe"
background-mode="true"></c4d-video-player-container>
background-mode></c4d-video-player-container>
</c4d-background-media>
</c4d-leadspace>
`;
Expand Down Expand Up @@ -480,7 +480,7 @@ export const MediumWithVideo = (args) => {
<c4d-background-media slot="image" opacity="100">
<c4d-video-player-container
video-id="0_ibuqxqbe"
background-mode="true"></c4d-video-player-container>
background-mode></c4d-video-player-container>
</c4d-background-media>
</c4d-leadspace>
`;
Expand Down Expand Up @@ -635,7 +635,7 @@ export const ShortWithVideo = (args) => {
<c4d-background-media slot="image" opacity="100">
<c4d-video-player-container
video-id="0_ibuqxqbe"
background-mode="true"></c4d-video-player-container>
background-mode></c4d-video-player-container>
</c4d-background-media>
</c4d-leadspace>
`;
Expand Down Expand Up @@ -754,7 +754,7 @@ export const CenteredWithVideo = (args) => {
<c4d-background-media slot="image" opacity="100">
<c4d-video-player-container
video-id="0_ibuqxqbe"
background-mode="true"></c4d-video-player-container>
background-mode></c4d-video-player-container>
</c4d-background-media>
</c4d-leadspace>
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license
*
* Copyright IBM Corp. 2020, 2023
* Copyright IBM Corp. 2020, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -82,6 +82,42 @@ export const withLightboxMediaViewer = (args) => {
`;
};

export const autoplay = (args) => {
const { aspectRatio, caption, hideCaption, thumbnail, videoId } =
args?.VideoPlayer ?? {};
return html`
<c4d-video-player-container
auto-play
playing-mode="inline"
video-id=${videoId}
aspect-ratio=${aspectRatio}
caption=${caption}
?hide-caption=${hideCaption}
thumbnail=${thumbnail}></c4d-video-player-container>
`;
};

export const autoplayMuted = (args) => {
const { caption, hideCaption, thumbnail, videoId } = args?.VideoPlayer ?? {};
return html`
<style>
c4d-video-player-container[background-mode] {
display: block;
aspect-ratio: 16/9;
outline: 2px solid red;
}
</style>
<c4d-video-player-container
auto-play
muted
playing-mode="inline"
video-id=${videoId}
caption=${caption}
?hide-caption=${hideCaption}
thumbnail=${thumbnail}></c4d-video-player-container>
`;
};

aspectRatio4x3.story = {
name: 'Aspect ratio 4:3',
parameters: {
Expand Down Expand Up @@ -171,6 +207,62 @@ withLightboxMediaViewer.story = {
},
};

autoplay.story = {
name: 'Autoplay',
parameters: {
knobs: {
VideoPlayer: () => {
return {
aspectRatio: '4x3',
caption: text('Custom caption (caption):', ''),
hideCaption: boolean('Hide caption (hideCaption):', false),
thumbnail: text('Custom thumbnail (thumbnail):', ''),
videoId: '0_ibuqxqbe',
};
},
},
propsSet: {
default: {
VideoPlayer: {
aspectRatio: '4x3',
caption: '',
hideCaption: false,
thumbnail: '',
videoId: '0_ibuqxqbe',
},
},
},
},
};

autoplayMuted.story = {
name: 'Autoplay muted',
parameters: {
knobs: {
VideoPlayer: () => {
return {
aspectRatio: '4x3',
caption: text('Custom caption (caption):', ''),
hideCaption: boolean('Hide caption (hideCaption):', false),
thumbnail: text('Custom thumbnail (thumbnail):', ''),
videoId: '0_ibuqxqbe',
};
},
},
propsSet: {
default: {
VideoPlayer: {
aspectRatio: '4x3',
caption: '',
hideCaption: false,
thumbnail: '',
videoId: '0_ibuqxqbe',
},
},
},
},
};

export default {
title: 'Components/Video player',
decorators: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ class C4DVideoPlayerComposite extends HybridRenderMixin(
@property({ type: Boolean, attribute: 'auto-play' })
autoPlay = false;

/**
* `true` load videos with sound muted.
*/
@property({ type: Boolean, attribute: 'muted' })
muted = false;

/**
* The embedded Kaltura player element (that has `.sendNotification()`, etc. APIs), keyed by the video ID.
*/
Expand Down Expand Up @@ -190,7 +196,7 @@ class C4DVideoPlayerComposite extends HybridRenderMixin(
/**
* `true` to autoplay, mute, and hide player UI.
*/
@property({ type: Boolean, attribute: 'background-mode' })
@property({ type: Boolean, attribute: 'background-mode', reflect: true })
backgroundMode = false;

/**
Expand All @@ -214,7 +220,7 @@ class C4DVideoPlayerComposite extends HybridRenderMixin(
/**
* The current playback state
*/
@property()
@property({ type: Boolean })
isPlaying = false;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,45 +168,54 @@ export const C4DVideoPlayerContainerMixin = <
const storedValue = localStorage.getItem(
`${this.prefersAutoplayStorageKey}`
);
const returnValue =
storedValue === null ? null : Boolean(parseInt(storedValue, 10));
return returnValue;

if (storedValue === null) {
return !window.matchMedia('(prefers-reduced-motion: reduce)').matches;
} else {
return Boolean(parseInt(storedValue, 10));
}
}

_getPlayerOptions(backgroundMode = false) {
_getPlayerOptions() {
const { backgroundMode, autoPlay, muted } =
this as unknown as C4DVideoPlayerComposite;
let playerOptions = {};

if (backgroundMode) {
const storedMotionPreference: boolean | null =
this._getAutoplayPreference();

let autoplayPreference: boolean | undefined;

if (storedMotionPreference === null) {
autoplayPreference = !window.matchMedia(
'(prefers-reduced-motion: reduce)'
).matches;
} else {
autoplayPreference = storedMotionPreference;
}
playerOptions = {
'topBarContainer.plugin': false,
'controlBarContainer.plugin': false,
'largePlayBtn.plugin': false,
'loadingSpinner.plugin': false,
'unMuteOverlayButton.plugin': false,
'EmbedPlayer.DisableVideoTagSupport': false,
loop: true,
autoMute: true,
autoPlay: autoplayPreference,
// Turn off CTA's including mid-roll card and end cards.
'ibm.callToActions': false,
// Turn off captions display, background/ambient videos have no
// audio.
closedCaptions: {
plugin: false,
},
};
const autoplayPreference = this._getAutoplayPreference();

switch (true) {
case autoPlay:
playerOptions = {
autoMute: muted,
autoPlay: autoplayPreference,
};
break;

case backgroundMode:
playerOptions = {
'topBarContainer.plugin': false,
'controlBarContainer.plugin': false,
'largePlayBtn.plugin': false,
'loadingSpinner.plugin': false,
'unMuteOverlayButton.plugin': false,
'EmbedPlayer.DisableVideoTagSupport': false,
loop: true,
autoMute: true,
autoPlay: autoplayPreference,
// Turn off CTA's including mid-roll card and end cards.
'ibm.callToActions': false,
// Turn off captions display, background/ambient videos have no
// audio.
closedCaptions: {
plugin: false,
},
};
break;

default:
playerOptions = {
autoMute: muted,
};
break;
}

return playerOptions;
Expand All @@ -219,7 +228,7 @@ export const C4DVideoPlayerContainerMixin = <
* @private
*/
// Not using TypeScript `private` due to: microsoft/TypeScript#17744
async _embedVideoImpl(videoId: string, backgroundMode = false) {
async _embedVideoImpl(videoId: string) {
const doc = Object.prototype.hasOwnProperty.call(this, 'getRootNode')
? (this.getRootNode() as Document | ShadowRoot)
: this.ownerDocument;
Expand All @@ -240,7 +249,7 @@ export const C4DVideoPlayerContainerMixin = <
const embedVideoHandle = await KalturaPlayerAPI.embedMedia(
videoId,
playerId,
this._getPlayerOptions(backgroundMode)
this._getPlayerOptions()
);
const { width, height } = await KalturaPlayerAPI.api(videoId);
videoPlayer.style.setProperty('--native-file-width', `${width}px`);
Expand All @@ -264,15 +273,15 @@ export const C4DVideoPlayerContainerMixin = <
* @param videoId The video ID.
* @internal
*/
_embedMedia = async (videoId: string, backgroundMode = false) => {
_embedMedia = async (videoId: string) => {
const { _requestsEmbedVideo: requestsEmbedVideo } = this;
const requestEmbedVideo = requestsEmbedVideo[videoId];

if (requestEmbedVideo) {
return requestEmbedVideo;
}

const promiseEmbedVideo = this._embedVideoImpl(videoId, backgroundMode);
const promiseEmbedVideo = this._embedVideoImpl(videoId);

this._setRequestEmbedVideoInProgress(videoId, promiseEmbedVideo);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class C4DVideoPlayer extends FocusMixin(StableSelectorMixin(LitElement)) {
private _renderContent() {
const { contentState, name, thumbnailUrl, backgroundMode } = this;
return contentState === VIDEO_PLAYER_CONTENT_STATE.THUMBNAIL &&
!backgroundMode
!backgroundMode &&
!this.autoplay
? html`
<div class="${c4dPrefix}--video-player__video" part="video">
<button
Expand Down Expand Up @@ -184,9 +185,15 @@ class C4DVideoPlayer extends FocusMixin(StableSelectorMixin(LitElement)) {
/**
* `true` to autoplay, mute video, and hide UI
*/
@property({ attribute: 'background-mode', reflect: true })
@property({ attribute: 'background-mode', reflect: true, type: Boolean })
backgroundMode = false;

/**
* `true` to autoplay
*/
@property({ attribute: 'auto-play', reflect: true, type: Boolean })
autoplay = false;

/**
* Custom video description. This property should only be set when using `playing-mode="lightbox"`
*/
Expand Down Expand Up @@ -285,7 +292,12 @@ class C4DVideoPlayer extends FocusMixin(StableSelectorMixin(LitElement)) {
(this.parentElement as C4DVideoPlayerContainer)?.backgroundMode
);

const parentIsAutoplay = Boolean(
(this.parentElement as C4DVideoPlayerContainer)?.autoPlay
);

this.backgroundMode = parentIsBackground;
this.autoplay = parentIsAutoplay;
}

/**
Expand Down

0 comments on commit 3799b6d

Please sign in to comment.