RFC: getVideoPlayerOptions #86
Replies: 3 comments 1 reply
-
I like the idea of shared types for the configuration/props of the player. This types are then consumed by the player component to generate the exposed props that I think are the same everywhere Also for the player there are basic JS stuff that can be shared that are framework agnostic I think like:
this will leave only the loading of the player to be handled by the particularities of the framework |
Beta Was this translation helpful? Give feedback.
-
I really like the idea! One small concern from the Vue/Nuxt part regarding this RFC. I wanted to use your types to type certain part of the application but due to bug in Vue and then in Nuxt it is not possible so I needed to copy the types to the app to make it work. If this bug will be finally fixed, I am fully into this idea. I mean, dont wait for me with it. I will just make it work somehow. Small additional comment (maybe an idea for the next RFC) -> Could we also do something similar with OGImage? I looked at how it is implemented in Next, Svelte and Nuxt and I noticed this: const TWITTER_CARD = "summary_large_image";
const OG_IMAGE_WIDTH = 2400;
const OG_IMAGE_WIDTH_RESIZE = 1200;
const OG_IMAGE_HEIGHT = 1254;
const options = {
...props,
crop: props.crop || "fill",
gravity: props.gravity || "center",
height: props.height || OG_IMAGE_HEIGHT,
src: props.src,
width: props.width || OG_IMAGE_WIDTH,
widthResize: props.width || OG_IMAGE_WIDTH_RESIZE,
};
let width =
typeof options.width === "string" ? parseInt(options.width) : options.width;
let height =
typeof options.height === "string"
? parseInt(options.height)
: options.height;
// Resize the height based on the widthResize property
if (typeof height === "number" && typeof width === "number") {
height = (OG_IMAGE_WIDTH_RESIZE / width) * height;
}
width = OG_IMAGE_WIDTH_RESIZE;
// Render the final URLs. We use two different format versions to deliver
// webp for Twitter as it supports it (and we can control with tags) where
// other platforms may not support webp, so we deliver jpg
const { url: ogImageUrl } = useCldImageUrl({
options: {
...options,
format: props.format || "jpg",
},
});
const { url: twitterImageUrl } = useCldImageUrl({
options: {
...options,
format: props.format || "webp",
},
}); I think that this functionality (at least more or less) could be stored in cloudinary util so that we in the frameworks can just get the values from it. WDYT? |
Beta Was this translation helpful? Give feedback.
-
Pull in autoPlay normalization via: cloudinary-community/next-cloudinary#350 |
Beta Was this translation helpful? Give feedback.
-
CldVideoPlayer is the recommended way to embed Cloudinary videos in a Next.js, Svelte, or Nuxt application. It's a wrapper of the Cloudinary Video Player which works in two ways: by dropping in a Script with CSS or by importing a node module.
CldVideoPlayer currently utilizes the Script installation method, which is a bit beyond the scope of this, but ultimately it requires a group of options to be passed into it in order to initialize and make use of the wide variety of features available to the Video Player.
In order to provide as much parity as possible between the libraries maintaining a CldVideoPlayer component, the maintainers and contributors must rewrite or copy and paste similar code within each of their frameworks, which is slow and prone to creating implementation differences. To help alleviate this, we can abstract some of the work to a utility library, much like we're currently doing for building URLs with CldImage.
The Challenge
Unlike CldImage, CldVideoPlayer doesn't take a URL as the primary input, and instead takes an object alongside the public ID which is composed of the different options available. This means there's not a single interface that can compose the entirety of CldVideoPlayer.
Additionally, some of the initialization and work needed to manage the component is different depending on the framework, leaving no point to try to deduplicate that work.
Proposed Solution
While we can't fully abstract the component into a single function, we can think about how we can compose different parts in a reusable fashion.
This proposal suggests to abstract out the options that are passed into the player upon initialization as well as the Types that are used, both from the Cloudinary Player itself, but also the props that are passed in as part of the options configuration.
getVideoPlayerOptions
The getVideoPlayerOptions function will compose the options that need to be passed into the Cloudinary Video Player videoPlayer method upon initialization.
Usage would look like the following:
This will simplify the ability to support all Player features while looking forward to creating different API surfaces for a better Video Player developer experience.
Types
There are two Types that are needed to be maintained for the Player:
Cloudinary Video Player (which are not publicly available)
getVideoPlayerOptions
Cloudinary Video Player types can be maintained in a new utility package of @cloudinary-util such as @cloudinary-util/types, which will make it easy to import these types into any project, though with this abstract, may possibly be no longer needed in the framework layer.
getVideoPlayerOptions will be the primary interface that the frameworks interact with, which can be used as the foundational interface that creates the component's Types, for instance
Issues
Beta Was this translation helpful? Give feedback.
All reactions