Skip to content

Commit

Permalink
Merge pull request #430 from cloudinary/ME-7140-duplicate-source-calls
Browse files Browse the repository at this point in the history
ME-7140-duplicate-source-calls
  • Loading branch information
tsi authored Sep 12, 2023
2 parents fc31ccc + 3ddea5d commit 90faa65
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 43 deletions.
6 changes: 3 additions & 3 deletions docs/_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<script type="text/javascript">
window.addEventListener('load', function(){

var player = cloudinary.videoPlayer('player', {
const player = cloudinary.videoPlayer('player', {
cloud_name: 'demo',
publicId: 'snow_horses',
info: { title: 'Snow Horses', subtitle: 'A movie about horses' },
Expand Down Expand Up @@ -74,10 +74,10 @@ <h3 class="mt-4">Example Code:</h3>
<code class="language-javascript">

// Initialize player
var player = cloudinary.videoPlayer('player', { cloud_name: 'demo' });
const player = cloudinary.videoPlayer('player', { cloud_name: 'demo' });

// Define source
var source = { publicId: 'snow_horses', info: { title: 'Snow Horses', subtitle: 'A movie about horses' } };
const source = { publicId: 'snow_horses', info: { title: 'Snow Horses', subtitle: 'A movie about horses' } };

// Play source
player.source(source);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h3 class="mt-4">Some code examples:</h3>
<li><a href="./components.html">Components</a></li>
<li><a href="./recommendations.html">Recommendations</a></li>
<li><a href="./fluid.html">Fluid Layouts</a></li>
<li><a href="./aiHighlightsGraph.html">AI Highlights Graph</a></li>
<li><a href="./highlights-graph.html">AI Highlights Graph</a></li>
<li><a href="./vast-vpaid.html">VAST & VPAID Support</a></li>
<li><a href="./360.html">360 Videos</a></li>
<li><a href="./floating-player.html">Floating Player</a></li>
Expand Down
14 changes: 11 additions & 3 deletions src/plugins/cloudinary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import { applyWithProps } from 'utils/apply-with-props';
import { sliceAndUnsetProperties } from 'utils/slicing';
import { isKeyInTransformation } from 'utils/cloudinary';
import { assign } from 'utils/assign';
import { isFunction } from 'utils/type-inference';
import Playlistable from 'mixins/playlistable';
import plugins from 'plugins';
import {
normalizeOptions,
mergeTransformations,
codecShorthandTrans,
extendCloudinaryConfig
} from './common';
import Playlistable from 'mixins/playlistable';
import VideoSource from './models/video-source/video-source';
import EventHandlerRegistry from './event-handler-registry';
import AudioSource from './models/audio-source/audio-source';
import { isFunction } from '../../utils/type-inference';

const DEFAULT_PARAMS = {
transformation: {},
Expand Down Expand Up @@ -79,9 +80,16 @@ class CloudinaryContext extends mixin(Playlistable) {
}

_source = src;
if (!options.skipRefresh) {

const isDashRequired = options.sourceTypes && options.sourceTypes.some(s => s.includes('dash'));
if (plugins.dashPlugin && isDashRequired) {
plugins.dashPlugin().then(() => {
refresh();
});
} else if (!options.skipRefresh) {
refresh();
}

this.player.trigger('cldsourcechanged', { source: src });

return _chainTarget;
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/cloudinary/models/video-source/video-source.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import BaseSource from '../base-source';
import ImageSource from '../image-source';
import { normalizeOptions, isSrcEqual, isRawUrl, mergeTransformations } from '../../common';
import { default as vjs } from 'video.js';
import { sliceAndUnsetProperties } from 'utils/slicing';
import { assign } from 'utils/assign';
import { objectToQuerystring } from 'utils/querystring';
import { default as vjs } from 'video.js';
import { castArray } from 'utils/array';
import { SOURCE_TYPE } from 'utils/consts';
import {
CONTAINER_MIME_TYPES,
DEFAULT_POSTER_PARAMS,
DEFAULT_VIDEO_PARAMS,
VIDEO_SUFFIX_REMOVAL_PATTERN
} from './video-source.const';
import { formatToMimeTypeAndTransformation, isCodecAlreadyExist, normalizeFormat } from './video-source.utils';
import { castArray } from '../../../../utils/array';
import { SOURCE_TYPE } from '../../../../utils/consts';
import { normalizeOptions, isSrcEqual, isRawUrl, mergeTransformations } from '../../common';
import BaseSource from '../base-source';
import ImageSource from '../image-source';

let objectId = 0;

Expand Down
30 changes: 0 additions & 30 deletions src/video-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,6 @@ class VideoPlayer extends Utils.mixin(Eventable) {
};

_setVideoJsListeners(ready) {

// Prevent flash of error message while lazy-loading plugins.
videojs.hook('beforeerror', (player, err) => {
if (err && err.code === 3 && this.loadingLazyPlugins) {
err = null;
}
return err;
});


this.videojs.on(PLAYER_EVENT.ERROR, () => {
const error = this.videojs.error();
if (error) {
Expand Down Expand Up @@ -208,21 +198,6 @@ class VideoPlayer extends Utils.mixin(Eventable) {
this._initSeekThumbs();
}

async _initLazyPlugins(options) {
this.loadingLazyPlugins = true;

await this._initDash(options);

this.loadingLazyPlugins = false;
}

async _initDash(options) {
const isDashRequired = options.sourceTypes && options.sourceTypes.some(s => s.includes('dash'));
if (plugins.dashPlugin && isDashRequired) {
await plugins.dashPlugin();
}
}

_isFullScreen() {
return this.videojs.player().isFullscreen();
}
Expand Down Expand Up @@ -584,11 +559,6 @@ class VideoPlayer extends Utils.mixin(Eventable) {
const videoReadyTimeout = this.videojs.options_.videoTimeout || 55000;
this.reTryVideo(maxTries, videoReadyTimeout);

// Lazy loaded plugins
this._initLazyPlugins(options).then(() => {
return this.videojs.cloudinary.source(publicId, options);
});

return this.videojs.cloudinary.source(publicId, options);
}

Expand Down

0 comments on commit 90faa65

Please sign in to comment.