MediaProviders
4 days ago
ProvidersPlaceholder
4 days ago
audioPresets
4 days ago
branding
6 months ago
chapters
2 years ago
components
4 days ago
media
4 days ago
overlays
4 days ago
presets
4 days ago
services
4 years ago
settings
1 month ago
styles
1 year ago
tracks
4 days ago
BlockInspectorControls.js
4 days ago
BlockInspectorControls.scss
4 days ago
Editing.js
1 year ago
LinkPlaceholder.js
1 month ago
Player.js
1 month ago
Preview.js
2 years ago
ProUpgradeModal.js
1 month ago
VisibilityEditor.js
6 months ago
audio-placeholder.js
4 days ago
helpers.js
5 years ago
options.js
4 days ago
placeholder.js
4 days ago
Player.js
178 lines
| 1 | import { |
| 2 | PrestoPlayer, |
| 3 | PrestoSearchBarUi, |
| 4 | } from "@presto-player/components-react"; |
| 5 | import { getProvider } from "../util"; |
| 6 | import { useRef, useLayoutEffect } from "@wordpress/element"; |
| 7 | import { useSelect } from "@wordpress/data"; |
| 8 | import { convertHex } from "../../../shared/util"; |
| 9 | |
| 10 | export default (props) => { |
| 11 | const { |
| 12 | src, |
| 13 | classes, |
| 14 | preset, |
| 15 | branding, |
| 16 | attributes, |
| 17 | adminPreview, |
| 18 | currentTime, |
| 19 | preload = "metadata", |
| 20 | overlays, |
| 21 | type, |
| 22 | } = props; |
| 23 | |
| 24 | const ref = useRef(); |
| 25 | const { |
| 26 | previewThumbnail, |
| 27 | chapters, |
| 28 | poster, |
| 29 | mutedOverlay, |
| 30 | mutedPreview, |
| 31 | title, |
| 32 | } = attributes; |
| 33 | |
| 34 | const { youtube, playerCSS } = useSelect((select) => { |
| 35 | return { |
| 36 | youtube: select("presto-player/player")?.youtube(), |
| 37 | playerCSS: select("presto-player/player")?.playerCSS(), |
| 38 | }; |
| 39 | }); |
| 40 | |
| 41 | useLayoutEffect(() => { |
| 42 | ref.current.src = src; |
| 43 | ref.current["data-css"] = playerCSS; |
| 44 | ref.current.classes = classes; |
| 45 | ref.current.currentTime = currentTime; |
| 46 | ref.current.overlays = JSON.stringify(overlays); |
| 47 | ref.current.isAdmin = true; |
| 48 | ref.current.preload = preload; |
| 49 | ref.current.preset = JSON.stringify(preset); |
| 50 | ref.current.youtube = { |
| 51 | channelId: youtube?.channel_id, |
| 52 | }; |
| 53 | ref.current.tracks = [ |
| 54 | ...(!!preset?.captions |
| 55 | ? [ |
| 56 | { |
| 57 | kind: "captions", |
| 58 | label: "English", |
| 59 | srclang: "en", |
| 60 | src: "/path/to/captions.en.vtt", |
| 61 | default: true, |
| 62 | }, |
| 63 | ] |
| 64 | : []), |
| 65 | ]; |
| 66 | ref.current.branding = JSON.stringify(branding); |
| 67 | ref.current.chapters = JSON.stringify(chapters); |
| 68 | ref.current.blockAttributes = attributes; |
| 69 | ref.current.poster = poster || previewThumbnail; |
| 70 | ref.current.provider = type === "audio" ? "audio" : getProvider(src); |
| 71 | ref.current.mediaTitle = title; |
| 72 | }, [ |
| 73 | src, |
| 74 | classes, |
| 75 | preset, |
| 76 | branding, |
| 77 | attributes, |
| 78 | adminPreview, |
| 79 | currentTime, |
| 80 | preload, |
| 81 | overlays, |
| 82 | type, |
| 83 | ]); |
| 84 | |
| 85 | const mutedOverlayContent = () => { |
| 86 | return ( |
| 87 | <div |
| 88 | className="presto-player__overlay is-image" |
| 89 | style={{ |
| 90 | position: "absolute", |
| 91 | width: `${mutedOverlay?.width || 100}%`, |
| 92 | left: `${(mutedOverlay?.focalPoint?.x || 0.5) * 100}%`, |
| 93 | top: `${(mutedOverlay?.focalPoint?.y || 0.5) * 100}%`, |
| 94 | }} |
| 95 | > |
| 96 | <img |
| 97 | src={mutedOverlay?.src} |
| 98 | style={{ |
| 99 | transform: "translateX(-50%) translateY(-50%)", |
| 100 | }} |
| 101 | /> |
| 102 | </div> |
| 103 | ); |
| 104 | }; |
| 105 | |
| 106 | return ( |
| 107 | <div |
| 108 | className={"wp-block-video presto-block-video"} |
| 109 | style={ |
| 110 | type === "audio" |
| 111 | ? { |
| 112 | "--presto-player-border-radius": `${preset?.border_radius}px`, |
| 113 | ...(preset?.background_color |
| 114 | ? { |
| 115 | "--plyr-audio-controls-background": preset.background_color, |
| 116 | } |
| 117 | : { "--plyr-audio-controls-background": branding?.color }), |
| 118 | ...(preset?.control_color |
| 119 | ? { |
| 120 | "--plyr-audio-control-color": preset.control_color, |
| 121 | "--plyr-range-thumb-background": preset.control_color, |
| 122 | "--plyr-range-fill-background": preset.control_color, |
| 123 | "--plyr-audio-progress-buffered-background": convertHex( |
| 124 | preset.control_color || branding?.color || "#00b3ff", |
| 125 | 0.5 |
| 126 | ), |
| 127 | } |
| 128 | : { |
| 129 | "--plyr-audio-control-color": "#ffffff", |
| 130 | "--plyr-range-thumb-background": "#ffffff", |
| 131 | "--plyr-range-fill-background": "#ffffff", |
| 132 | }), |
| 133 | "--plyr-range-thumb-shadow": `0px`, |
| 134 | } |
| 135 | : { |
| 136 | "--presto-player-border-radius": `${preset?.border_radius}px`, |
| 137 | "--presto-player-aspect-ratio": |
| 138 | attributes?.ratio === "original" |
| 139 | ? "unset" |
| 140 | : attributes?.ratio?.replace(":", "/") || "16/9", |
| 141 | ...(preset?.caption_background |
| 142 | ? { "--plyr-captions-background": preset.caption_background } |
| 143 | : {}), |
| 144 | ...(branding?.color |
| 145 | ? { |
| 146 | "--plyr-color-main": `var(--presto-player-highlight-color, ${branding.color})`, |
| 147 | } |
| 148 | : {}), |
| 149 | "--presto-player-email-border-radius": `${ |
| 150 | preset?.email_collection?.border_radius || 0 |
| 151 | }px`, |
| 152 | "--presto-player-logo-width": `${branding?.logo_width || 75}px`, |
| 153 | } |
| 154 | } |
| 155 | > |
| 156 | <PrestoPlayer ref={ref}> |
| 157 | <div slot="player-end"> |
| 158 | {!!preset.search?.enabled && ( |
| 159 | <PrestoSearchBarUi |
| 160 | style={{ |
| 161 | position: "absolute", |
| 162 | top: "15px", |
| 163 | right: "23px", |
| 164 | zIndex: 1, |
| 165 | }} |
| 166 | placeholder={preset.search?.placeholder} |
| 167 | /> |
| 168 | )} |
| 169 | {mutedPreview?.enabled && |
| 170 | mutedOverlay?.enabled && |
| 171 | mutedOverlayContent()} |
| 172 | {adminPreview} |
| 173 | </div> |
| 174 | </PrestoPlayer> |
| 175 | </div> |
| 176 | ); |
| 177 | }; |
| 178 |