Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/es-modules/poster.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ <h4>Raw URL - default with no poster image</h4>
<video id="player-raw" playsinline controls class="cld-video-player cld-fluid"></video>
</div>

<div class="video-container mb-4">
<h4>Applet poster (poster: true)</h4>
<h6>Uses applet service URL for poster</h6>
<video id="player-applet-poster" playsinline controls class="cld-video-player cld-fluid"></video>
</div>

<p class="mt-4">
<a href="https://cloudinary.com/documentation/cloudinary_video_player"
>Full documentation</a
Expand Down Expand Up @@ -89,6 +95,12 @@ <h4>Raw URL - default with no poster image</h4>
cloudName: 'demo',
publicId: 'https://res.cloudinary.com/demo/video/upload/sp_auto/sea_turtle.m3u8'
});

const playerAppletPoster = videoPlayer('player-applet-poster', {
cloudName: 'demo',
publicId: 'snow_horses',
poster: true
});
</script>

<!-- Bootstrap -->
Expand Down
30 changes: 30 additions & 0 deletions docs/poster.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
publicId: 'https://res.cloudinary.com/demo/video/upload/sp_auto/sea_turtle.m3u8'
});

player5 = cloudinary.videoPlayer('player-applet-poster', {
cloud_name: 'demo',
publicId: 'snow_horses',
poster: true
});

}, false);
</script>

Expand Down Expand Up @@ -113,6 +119,17 @@ <h4>Raw URL - default with no poster image</h4>
></video>
</div>

<div class="video-container mb-4">
<h4>Applet poster (poster: true)</h4>
<h6>Uses applet service URL for poster</h6>
<video
id="player-applet-poster"
playsinline
controls
class="cld-video-player cld-fluid"
></video>
</div>

<p class="mt-4">
<a href="https://cloudinary.com/documentation/video_player_api_reference#posteroptions">Full documentation</a>
</p>
Expand Down Expand Up @@ -151,6 +168,13 @@ <h3 class="mt-4">Example Code:</h3>
class="cld-video-player cld-fluid"
&lt;/video&gt;

&lt;video
id="player-applet-poster"
playsinline
controls
class="cld-video-player cld-fluid"
&lt;/video&gt;

</code>
<code class="language-javascript">

Expand Down Expand Up @@ -179,6 +203,12 @@ <h3 class="mt-4">Example Code:</h3>
publicId: 'https://res.cloudinary.com/demo/video/upload/sp_auto/sea_turtle.m3u8'
});

player5 = cloudinary.videoPlayer('player-applet-poster', {
cloud_name: 'demo',
publicId: 'snow_horses',
poster: true
});

</code>
</pre>
</div>
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/cloudinary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,14 @@ class CloudinaryContext {
options.cloudinaryConfig = extendCloudinaryConfig(this.cloudinaryConfig(), options.cloudinaryConfig || {});
options.transformation = mergeTransformations(this.transformation(), options.transformation || {});
options.sourceTransformation = options.sourceTransformation || this.sourceTransformation();
options.sourceTypes = options.sourceTypes || this.sourceTypes();
options.poster = options.poster || posterOptionsForCurrent();
options.sourceTypes = options.sourceTypes || this.sourceTypes();


const defaultPosterOptions = posterOptionsForCurrent();
const userPosterOptions = options.posterOptions || {};
options.poster = options.poster || defaultPosterOptions;
options.posterOptions = Object.assign({}, defaultPosterOptions, userPosterOptions);

options.queryParams = Object.assign(options.queryParams || {}, options.allowUsageReport ? { _s: `vp-${VERSION}` } : {});

if (options.sourceTypes.indexOf('audio') > -1) {
Expand Down
27 changes: 24 additions & 3 deletions src/plugins/cloudinary/models/video-source/video-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
hasCodec,
normalizeFormat
} from './video-source.utils';
import { normalizeOptions, isSrcEqual, isRawUrl, mergeTransformations } from '../../common';
import { normalizeOptions, isSrcEqual, isRawUrl, mergeTransformations, getCloudinaryUrlPrefix } from '../../common';
import { utf8ToBase64 } from 'utils/utf8Base64';
import Transformation from '@cloudinary/url-gen/backwards/transformation';
import BaseSource from '../base-source';
import ImageSource from '../image-source';

Expand Down Expand Up @@ -127,9 +129,28 @@ class VideoSource extends BaseSource {
}

options.cloudinaryConfig = options.cloudinaryConfig || this.cloudinaryConfig();

options.resource_type = this.resourceType() || options.resource_type;


if (publicId === true) {
const urlPrefix = getCloudinaryUrlPrefix(options.cloudinaryConfig);
const deliveryType = this.getInitOptions().type || 'upload';
const base64PublicId = utf8ToBase64(this.publicId());
let appletUrl = `${urlPrefix}/_applet_/video_service/elements/${deliveryType}/${base64PublicId}/poster`;

const transformation = this.getInitOptions().posterOptions?.transformation;
if (transformation) {
const transformationString = new Transformation(transformation).toString();
appletUrl += `?tx=${transformationString}`;
}

this._poster = new ImageSource(appletUrl, {
cloudinaryConfig: options.cloudinaryConfig
});

return this;
}

this._poster = new ImageSource(publicId, options);

return this;
Expand Down
5 changes: 5 additions & 0 deletions src/utils/get-analytics-player-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const filterDefaultsAndNulls = (obj) => Object.entries(obj).reduce((filtered, [k
}, {});

const getSourceOptions = (sourceOptions = {}) => ({
poster: (() => {
if (sourceOptions.poster === true) return 'auto';
if (typeof sourceOptions.poster === 'string') return 'url';
return undefined;
})(),
posterOptions: hasConfig(sourceOptions.posterOptions),
posterOptionsPublicId: sourceOptions.posterOptions && hasConfig(sourceOptions.posterOptions.publicId),
autoShowRecommendations: sourceOptions.autoShowRecommendations,
Expand Down
Loading