MediaPlayer
This component allows a consumer to play audio or video embeds from the following services: YouTube, Vimeo, SoundCloud and Spotify.
Basic Usage
import { MediaPlayer } from '@krakentech/coral';
<MediaPlayer url="https://www.youtube.com/watch?v=hJ17RoZgwfk" />(or allow optional cookies to play it right here)
Services
YouTube
<MediaPlayer url="https://www.youtube.com/watch?v=hJ17RoZgwfk" />(or allow optional cookies to play it right here)
Vimeo
<MediaPlayer url="https://vimeo.com/578586673" />(or allow optional cookies to play it right here)
SoundCloud
<MediaPlayer url="https://soundcloud.com/octopusenergy/ep-16-how-kraken-is-powering-a-transformation-at-octopus-and-beyond" />(or allow optional cookies to play it right here)
Spotify
<MediaPlayer url="https://open.spotify.com/episode/1DNK1CyWKkvxmxpbiPvQGe" />(or allow optional cookies to play it right here)
Unsupported
If an unsupported URL is given, the component will render the following message to warn of the issue.
<MediaPlayer url="https://player-widget.mixcloud.com/widget/iframe/?hide_cover=1&mini=1&feed=%2Fdublab%2Fel-marchante-tizita-radio-071524%2F" />MediaPlayer: Unsupported platform. Youtube, Vimeo and SoundCloud and Spotify are the platforms currently supported. Please provide a URL from one of those services to the "url" prop.
Properties
title
<MediaPlayer
url="https://www.youtube.com/embed/shT9-qX_y-w"
title="The title of the video."
/>(or allow optional cookies to play it right here)
aspectRatio
<MediaPlayer
url="https://www.youtube.com/embed/shT9-qX_y-w"
aspectRatio="9/16"
/>(or allow optional cookies to play it right here)
cookieKeyRequiredForConsent
A string that matches the granular cookie key used across your site. For example if the user can select granular cookies like “Marketing and Social Media”, you’ll need to provide the same key value for that cookie here: “marketing_and_social_media” to allow the media to be played on your site.
The CookiePreferences organism will automatically publish an event when the user accepts or rejects cookies, even granular ones, and the MediaPlayer will automatically subscribe to this event and either render the media or not depending on the user’s selection.
<MediaPlayer
url="https://www.youtube.com/embed/shT9-qX_y-w"
cookieKeyRequiredForConsent="marketing_and_social_media"
/>placeholderTitle
A string that will be used as the title of the placeholder when the media is not played because the cookies have not been accepted. The {platformName} placeholder will be replaced with the name of the platform in use (YouTube, Vimeo, SoundCloud, Spotify).
<MediaPlayer
url="https://www.youtube.com/embed/shT9-qX_y-w"
placeholderTitle="Play this on {platformName}"
/>placeholderSubtitle
A string that will be used as the subtitle of the placeholder when the media is not played because the cookies have not been accepted.
<MediaPlayer
url="https://www.youtube.com/embed/shT9-qX_y-w"
placeholderSubtitle="or allow optional cookies to play it right here"
/>placeholderImageUrl
A string that will be used as the background image of the placeholder when the media is not played because the cookies have not been accepted.
<MediaPlayer
url="https://www.youtube.com/embed/shT9-qX_y-w"
placeholderImageUrl="https://www.youtube.com/watch?v=hJ17RoZgwfk"
/>MediaPlayer, Storyblok and cookie consent
The issue: Consumers that use coral-storyblok components typically use them out of the box and initialise them by just putting all of the components inside the storyblokInit function . This is fine for most components, but what if you need to provide props on a particular component that’ll persist across an entire space?
To provide CoralBlokMediaPlayer with persistent values for cookieKeyRequiredForConsent and onSubtitleClicked you can override the default component initialisation by doing the following:
import {
CoralBlokMediaPlayer,
coralBloks,
} from '@krakentech/coral-storyblok/rsc';
import { apiPlugin, storyblokInit } from '@storyblok/react/rsc';
import type { ComponentProps } from 'react';
const CoralBlokMediaPlayerWithDefaults = (
props: ComponentProps<typeof CoralBlokMediaPlayer>
) => (
<CoralBlokMediaPlayer
blok={{
...props.blok,
cookieKeyRequiredForConsent: 'marketing_and_social_media',
onSubtitleClicked: () => {
// remove cookies, local storage and reload the page
},
}}
/>
);
export const getStoryblokApi = storyblokInit({
accessToken: process.env.storyblokAccessToken,
use: [apiPlugin],
apiOptions: {
region: 'eu',
},
components: {
...coralBloks,
coralBlokMediaPlayer: CoralBlokMediaPlayerWithDefaults,
},
});